+3 votes
in Class 12 by kratos

Explain defining objects of a class with syntax and a programming example.

1 Answer

+5 votes
by kratos
 
Best answer

The objects are declared after a class is defined. The object declaration create object of that class and memory is allocated for the created object. The object are created using the following syntax:
classname objectname1, objectname2,……………;
for 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.
For example:
obj1.getdata(5, 25);
here, getadata() 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.

...