Write a program to create a class CIRCLE with one
field as radius, used to calculate the area of a Circle. Create another class
RECTANGLE used to calculate the area of the rectangle which is a subclass
of CIRCLE class. Use the concept of single inheritance such that the radius
of circle class can be re-used as length in rectangle class. Take necessary
data members and member functions for both the classes to solve this
problem. All the data members are initialized through the constructors. Show the result by accessing the area method of both the classes through the
objects of rectangle class.
2 (Multilevel Inheritance) Modify the program no. 1 as follows:
Derive a class named as BOX from RECTANGLE class. Take necessary
data & member functions for this box class to calculate the volume of the
box. All the data members are initialized through the constructors. Show the
result by accessing the area method of circle and rectangle and the volume
method of box class through the objects of box class.
Comments
Leave a comment