Multiple choice technology web technology

In simple words, if we have a super class and n sub-classes, and based on data provided, we have to return the object of one of the sub-classes, we use a ___________

  1. Singleton

  2. Factory

  3. Builder

  4. Prototype

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The Factory pattern creates objects without specifying their exact class. When you have a superclass and multiple subclasses, and need to instantiate the appropriate subclass based on input data, a Factory method decides which class to instantiate and returns it. Singleton ensures one instance, Builder constructs complex objects step-by-step, and Prototype clones existing objects; none solve the conditional instantiation problem.