Code:
For Example
Box b1,b2;
Here b1 and b2 are the objects of class Box.
For example
class Box
{
private : int l,h,w;
public :
void get_data()
{
cout<<”enter the length width and height of box”;
cin>>l>>h>>w;
}
void display()
{
cout<<”the length of box is<<l;
cout<<”the height of box is<<h;
cout<<”the width of box is<<w;
}
};
main ()
{
Box b1,b2;
}
In above example b1 and b2 are the two objects of the class Box. Here the object b1 and b2 both have their own copy of variables l, h, w ,and created on the same line. The Object can be created on separate line
Box b1;
Box b2;
There is another place where objects can be created i.e. at the time of defining a class by placing objects name after the ending brace but before the semicolon of class.
class Box
{
members
}b1,b2;
Bookmarks