Rectangle class inherits members of Shape class Has one meth
Rectangle class inherits members of Shape class Has one method called \"getArea\" \"getArea\" method should return the area of a rectangle
Solution
Here is code:
class Shape {
//shape class have method getArea return
int getArea(int length, int width)
{
return length * width;
}
}
// rectangle extends shape
class Rectangle extends Shape {
int GetData(int l, int h)
{
return getArea(l, h);
}
public
static void main(String args[])
{
Rectangle obj = new Rectangle();
//get area of rectangle by GetDate
System.out.println(\"Area is \" + obj.GetData(5, 6));
}
}
Output:
Area is 30
