0% found this document useful (0 votes)
929 views6 pages

Object Oriented System Development Using UML, Java and Patterns

1. The document contains a 10 question multiple choice quiz about object oriented design patterns like Singleton, Composite, and State patterns. 2. Key concepts covered include the proper implementation of the Singleton pattern to ensure only one object is created, how the Composite pattern represents part-whole hierarchies, and how the State pattern allows an object's behavior to change based on its internal state. 3. The questions test understanding of when and how to apply various design patterns to modeling real-world problems, with examples like modeling a file system or programming structure.

Uploaded by

vit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
929 views6 pages

Object Oriented System Development Using UML, Java and Patterns

1. The document contains a 10 question multiple choice quiz about object oriented design patterns like Singleton, Composite, and State patterns. 2. Key concepts covered include the proper implementation of the Singleton pattern to ensure only one object is created, how the Composite pattern represents part-whole hierarchies, and how the State pattern allows an object's behavior to change based on its internal state. 3. The questions test understanding of when and how to apply various design patterns to modeling real-world problems, with examples like modeling a file system or programming structure.

Uploaded by

vit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

NPTEL Online Certification Courses

Indian Institute of Technology Kharagpur

Object Oriented System Development Using UML,


Java and Patterns
Assignment-10
TYPE OF QUESTION: MCQ/MSQ
Number of questions: 10 Total mark: 10 X 1 = 10
For each of the following questions one or more of the given options are correct. Choose the correct
options.

QUESTION 1:
Consider the following structure of a singleton class.

Which of the following modifiers for methods are not essential to the satisfactory working of the
singleton class?
a. uniqueInstance is static
b. getInstance() is static
c. singletonData is static
d. getSingletonData() is static
e. Singleton() is private
f. singletonOperation() is private
Correct Answer: d. getSingletonData() is static
f. singletonOperation() is private
Detailed Solution:

getSingletonData() and singletonOperation() is not deal with object creation or object return. So, it
need not be static or private.
QUESTION 2:
Which of the following describes the purpose of the State pattern correctly?
a. The behaviour of a class instance changes based on its state.
b. The state behaviour of a class is implemented using a doubly nested switch
c. The behaviour of the algorithm a class method can be changed at run time.
d. The state behaviour of a class is implemented in an abstract class and are inherited
by the concrete state classes.
e. Allows efficient implementation of synchronous state transition among a group of
objects
Correct Answer: a. The behavior of a class instance changes based on its state.
Detailed Solution:
State pattern is a behavioral pattern. Allows an object to alter its behavior when its state changes.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 3:

Consider the following Java AWT class hierarchy.

Observe that the containers can contain basic components such as buttons, canvas, and also some
containers. Which design pattern has been used?
a. Façade
b. Observer
c. Composite
d. Singleton
e. Law of Demeter
f.
MVC
Correct Answer: c. Composite

Detailed Solution: From the diagram, we can observe a composite relation between Component and
Container class.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 4:
Which of the following sentences are correct about the singleton design pattern?
a. It is creational pattern.
b. This pattern involves a single class which is responsible to create only a single
object.
c. Singleton object is always instantiated, even if the singleton object is never
required during a specific run of the application.
d. The constructor of the singleton is public
e. The accessibility of the instance variable of the singleton is declared public
Correct Answer: a. It is a creational pattern
b. This pattern involves a single class which is responsible to create only a single
object.

Detailed Solution:
Singleton pattern is a creational pattern and it involves a single class which is responsible for
creating only a single object.

QUESTION 5:
Which of the following is/are false about the State pattern?
a. State behaviour is localized in the state pattern solution.
b. The Singleton pattern may be used with the State pattern.
c. State transitions are made explicit in the state pattern solution.
d. State pattern makes it easier to add new states and transitions later in an
implementation.
e. Use of state pattern helps in realizing a computationally efficient implementation of a
state chart model

Correct Answer: e. Use of state pattern helps is realizing a computationally efficient


implementation of a state chart model
Detailed Solution:
State pattern does not help in realizing a computationally efficient implementation of a state chart
model.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 6:
For modelling which of the following design problems, composite pattern would be an appropriate
choice?
a. A book consists of Chapters, which in turn consist of sections and which in turn consist
of subsections.
b. A Car consists of a chassis, engine, 4 wheels, and 4 doors. The engine in turn consists of
battery, ignition chamber, and several Embedded Control Units (ECUs).
c. A program consists of functions, the functions consist of blocks of code, and the a block
of code in turn consists of statements and blocks of code.
d. A university consists of several schools, and each school consists of Departments.
e. A file system consists of a root directory. The root directory contains several directories.
Each directory can contain files and directories.

Correct Answer: c. A program consists of functions, the functions consist of blocks of code, and the
a block of code in turn consists of statements and blocks of code.
e. A file system consists of a root directory. The root directory contains several
directories. Each directory can contain files and directories.
Detailed Solution:
We can find Component, Composite and Leaf in problem description in option c and e.
QUESTION 7:
Following Java code for a Singleton class has been written by a programmer.

The Singleton does not work satisfactorily as there is bug in the code. Which line in the code has the
bug?
a. 1
b. 2
c. 3
d. 4
e. 5
f. 6
Correct Answer: e. 5

Detailed Solution:
Line no. 5 contain bug. Because, here without checking the object existence a new object is creating.
So, it may possible multiple objects creation of singleton class.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 8:

Which of the following characteristics of a class indicate the applicability of the Singleton
pattern?
a. The class has only a single member method.
b. The class has only a single field.
c. The reference to the single instance would be available to all other objects in the
system
d. The class should be restricted to have exactly one instance.
e. The class can at most be subclassed once.

Correct Answer: c. The reference to the single instance would be available to all other objects in
the system
d. The class should be restricted to have exactly one instance.

Detailed Solution:
Singleton ensure that class has only one instance and provide a global point to access it. So, option
c. and d. are correct.

QUESTION 9:
Consider the following structure of a singleton class, in which the method visibility information has
been omitted.

To make the singleton to work satisfactorily in a Java concurrent thread execution environment,
which methods must be declared synchronized?
a. getSingletonData()
b. getInstance()
c. singletonOperation()
d. Singleton()
Correct Answer: b. getInstance()
c. singletonOperation()

Detailed Solution:
Synchronized is used in getInstance() to make sure that there is exactly one thread in the block as
well as in singletonOperation().
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 10:
Which one of the following class diagram is the correct class model for a Unix-like directory
containg files, some of which can be directories?

a. A
b. B
c. C
d. D
e. E
f. F

Correct Answer: b. B

Detailed Solution:
Option b. is correct as Folder is an interface so, file and directory will implement it.

************END***********

You might also like