Whats in this post?
- Background and Explanation of the code
To copy code: Click “View Source” on the right of this code snippet.
Background and Explanation of the code
In this program, whenever we create an object of class rectangle with the statement rectangle r1; the data members length and breadth of object r1 will be initialized with the values 6 and 8 respectively by invoking the zero parameter constructor automatically.This method of initializing data members of objects using constructors is very simple and concise as there is no need to explicitly call the member function for each object separately.
Area of rectangle = 48