Why is a class called an object factory?

Question :

Why is a class called an object factory?

A class is called an object factory because objects are created from a class. An object is an instance of a class.

The following statements create two objects s1 and s2 of the class Student.

Student s1 = new Student();

Student s2 = new Student();

So, we have a single class Student but we can create as many objects as we want (like s1, s2, etc.) from that single class.

This is similar to what happens in a factory. Consider a factory which produces car. They have only a single design of a car but produce multiple cars from that single design. Things are similar in the world of classes and objects. There is a single definition of a particular class (like Student) but we can produce many Student objects (like s1, s2) from that single class.


Similar Questions


CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz