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.