arrow
arrow
arrow
Which of the following statements is correct about the class?
Question



Which of the following statements is correct about the class?

A.

An object is an instance of its class.

B.

A class is an instance of its object.

C.

An object is the instance of the data type of that class.

D.

More than one of the above

E.

None of the above

Correct option is A


A class in object-oriented programming (OOP) serves as a blueprint for creating objects. An object is an instance of a class, meaning it is a concrete realization of the structure and behavior defined within the class.
When a class is defined, no memory is allocated until an object of that class is created. The object represents a specific entity with attributes (data members) and behaviors (methods) as described in the class.
Example in C++:
class Car {
public:
string brand;
int speed;
};
int main() {
Car myCar; // 'myCar' is an instance (object) of the 'Car' class
myCar.brand = "Toyota";
myCar.speed = 120;
return 0;
}
Here, Car is a class, and myCar is an object (instance) of the Car class.
Since an object is an instance of its class, option (a) is correct.
Important Key Points:
1. Definition of a Class and Object: A class defines properties and behaviors, while an object represents a real-world entity based on that class.
2. Class vs. Object Relationship:
· A class acts as a template, and objects are created from it.
· Example: class Car defines what a car is, while Car myCar; creates a specific car.
3. Memory Allocation:
· A class does not consume memory until an object is instantiated.
· An object gets memory allocated for all its attributes when created.
4. Object as an Instance: An object is a concrete realization of the class structure and can hold different values in different instances.
5. Example in Python:
class Animal:
def __init__(self, name):
self.name = name
dog = Animal("Bulldog") # 'dog' is an object of class 'Animal'
· Here, dog is an instance of the class Animal.
6. Real-Life Analogy: A class is like a blueprint for a house, and objects are the actual houses built using that blueprint.
Knowledge Booster:
· A class is an instance of its object: Incorrect because a class defines an object, but it is not itself an instance.
· An object is the instance of the data type of that class: Objects belong to a class type, but they do not instantiate a "data type"—they instantiate a class.

Free Tests

Free
Must Attempt

UPTET Paper 1: PYP Held on 23rd Jan 2022 (Shift 1)

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon150 Marks
  • timerIcon150 Mins
languageIcon English
Free
Must Attempt

UPTET Paper 2 Social Science : PYP Held on 23rd Jan 2022 (Shift 2)

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon150 Marks
  • timerIcon150 Mins
languageIcon English
Free
Must Attempt

UPTET Paper 2 Maths & Science : PYP Held on 23rd Jan 2022 (Shift 2)

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon150 Marks
  • timerIcon150 Mins
languageIcon English
test-prime-package

Access ‘BPSC TRE (11-12)’ Mock Tests with

  • 60000+ Mocks and Previous Year Papers
  • Unlimited Re-Attempts
  • Personalised Report Card
  • 500% Refund on Final Selection
  • Largest Community
students-icon
354k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow