June 25, 2012

Gang of Four (GOF) Java Design Patterns Mock Exams (Page 01)

Gang of Four (GOF) Java Design Patterns Mock Exams.
Following are some questions on Java Design Patterns, which includes answers also:

Page 1

1) Which pattern is most appropriate when a decision must be
made at the time a class is instantiated?
Please choose only one answer:
A) Bridge
B) Composite
C) Factory Method
D) Command




Answer: C

2) Given the following scenario:
You want to create families of related objects, to be used interchangeably
 to configure you application. What is most appropriate GoF pattern to use?
Please choose only one answer:
A) Chain of Responsibility
B) Abstract Factory
C) Builder
D) Observer

Answer: B

3) It is also known as Virtual Constructor and it is used to define an interface
 for creating an object but letting the subclass decide which class to instantiate,
 this pattern is :
Please choose only one answer: 
A) Builder
B) Abstract Factory
C) Prototype
D) Factory Method

Answer: D

4) You want all the clients using class A to use the same instance of class A,
what should you do to achieve this goal?
Please choose only one answer:
A) mark class A final
B) mark class A abstract
C) apply the Singleton pattern to class A
D) apply the Memento pattern to class A

Anwer: C

1 comment: