Design Patterns Mock Test


This section presents you various set of Mock Tests related to Design Patterns Framework. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.

Questions and Answers

Design Patterns Mock Test I

Answer : D

Explanation

Design patterns represent the best practices used by experienced object-oriented software developers. Design patterns are solutions to general problems that software developers faced during software development. These solutions were obtained by trial and error by numerous software developers over quite a substantial period of time.

Answer : A

Explanation

In 1994, four authors Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides published a book titled Design Patterns - Elements of Reusable Object-Oriented Software which initiated the concept of Design Pattern in Software development. These authors are collectively known as Gang of Four (GOF).

Answer : A

Explanation

Design patterns can be classified in three categories: Creational, Structural and Behavioral patterns.

Answer : C

Explanation

Structural design patterns concern class and object composition. Concept of inheritance is used to compose interfaces and define ways to compose objects to obtain new functionalities.

Answer : D

Explanation

Factory pattern is one of most used design pattern in Java. This type of design pattern comes under creational pattern as this pattern provides one of the best ways to create an object. In Factory pattern, we create object without exposing the creation logic to the client and refer to newly created object using a common interface.

Answer : D

Explanation

Abstract Factory patterns work around a super-factory which creates other factories. This factory is also called as factory of factories. This type of design pattern comes under creational pattern as this pattern provides one of the best ways to create an object. In Abstract Factory pattern an interface is responsible for creating a factory of related objects without explicitly specifying their classes. Each generated factory can give the objects as per the Factory pattern.

Answer : D

Explanation

Singleton pattern is one of the simplest design patterns in Java. This type of design pattern comes under creational pattern as this pattern provides one of the best ways to create an object.This pattern involves a single class which is responsible to create an object while making sure that only single object gets created. This class provides a way to access its only object which can be accessed directly without need to instantiate the object of the class.

Q 10 - Can we create a clone of a singleton object?

A - true

B - false

Answer : A

Explanation

true. It is possible to get a clone of singleton object. Throw exception within the body of clone() method to prevent cloning.

Q 11 - If we serialize a singleton object and deserialize it then the result object will be same.

A - true

B - false

Answer : B

Explanation

false. Deserializing a serialized object will yield a different object.

Q 12 - Integer class is an example of Decorator pattern.

A - true

B - false

Answer : A

Explanation

true. Wrapper classes like Integer, Boolean uses Decorator pattern.

Q 13 - Runtime class is an example of singleton.

A - true

B - false

Answer : A

Explanation

true. Each java application uses Runtime as a single object.

Q 14 - Integer.valueOf is an example of Factory pattern.

A - false

B - true

Answer : B

Explanation

true. Integer.valueOf() returns a Integer instance representing the specified int value.

Q 15 - Event handling frameworks like swing, awt use Observer Pattern.

A - false

B - true

Answer : B

Explanation

true. Event handling frameworks like swing, awt use Observer Pattern.

Answer : A

Explanation

Builder pattern builds a complex object using simple objects and using a step by step approach. This builder is independent of other objects.

Answer : C

Explanation

Adapter pattern works as a bridge between two incompatible interfaces. This pattern involves a single class which is responsible to join functionalities of independent or incompatible interfaces.

Q 21 - Which of the following pattern builds a complex object using simple objects and using a step by step approach?

A - Builder Pattern

B - Bridge Pattern

C - Adapter Pattern

D - Filter Pattern

Answer : A

Explanation

Builder Pattern builds a complex object using simple objects and using a step by step approach. This builder is independent of other objects.

Q 22 - Which of the following pattern refers to creating duplicate object while keeping performance in mind?

A - Builder Pattern

B - Bridge Pattern

C - Prototype Pattern

D - Filter Pattern

Answer : C

Explanation

Prototype pattern refers to creating duplicate object while keeping performance in mind.

Q 23 - Which of the following pattern works as a bridge between two incompatible interfaces?

A - Builder Pattern

B - Adapter Pattern

C - Prototype Pattern

D - Filter Pattern

Answer : B

Explanation

Adapter pattern works as a bridge between two incompatible interfaces. This pattern involves a single class which is responsible to join functionalities of independent or incompatible interfaces.

Q 24 - Which of the following pattern is used when we need to decouple an abstraction from its implementation so that the two can vary independently?

A - Bridge Pattern

B - Adapter Pattern

C - Prototype Pattern

D - Filter Pattern

Answer : A

Explanation

Bridge pattern is used when we need to decouple an abstraction from its implementation so that the two can vary independently.

Q 25 - Which of the following pattern is used when creation of object directly is costly?

A - Bridge Pattern

B - Adapter Pattern

C - Prototype Pattern

D - Filter Pattern

Answer : A

Explanation

Prototype pattern is used when creation of object directly is costly.

Answer Sheet

Question Number Answer Key
1 D
2 A
3 A
4 B
5 C
6 A
7 D
8 D
9 D
10 A
11 B
12 A
13 A
14 B
15 B
16 A
17 D
18 B
19 C
20 B
21 A
22 C
23 B
24 A
25 A
design_pattern_questions_answers.htm
Advertisements