+3 votes
in Class 12 by kratos

Explain how objects of a class can be defined?

1 Answer

+3 votes
by kratos
 
Best answer

The objects are declared after a class is defined. The object declaration creates object of that class and memory is allocated for the created object.

The object are created using the following
syntax:

classname objectname1, objectname2,
example:
student obj1, obj2;
the obj1 and obj2 are the objects of class type student.
The object names are used to access the data members through member functions by invoking member functions.
example:
obj1.getdata(5, 25);

here, metadata() is the member function of a class student and function call is give using object obj1 which assign the value 5 and 25 to the data members of the class. The memory is allocated separately for data members of each object.

...