Java OCA OCP Practice Question 390

Question

Given:

class Main {/*from  w w  w .  jav a 2  s .  co  m*/
}

abstract class MyClass {
   Main m() {
      return n();
   }

   abstract Main n();
}

Which design pattern or principle is implemented?

  • A. DAO
  • B. Factory
  • C. IS-A
  • D. Object composition
  • E. Singleton


B is correct.

Note

Class Main is the object we are creating using the factory method.

Class MyClass is the abstract superclass for the factory.

Not shown is a class implementing class MyClass that actually creates the object.




PreviousNext

Related