a java program to calculate the area of different shapes using Multilevel Inheritance
class Shape
{
int i=10,j=20; void area(){ System.out.println("Find area of rectangle and square:"); }
}
class Rectangle extends Shape
{
int l=10,b=5; void areaOfRectangle(){ area(); System.out.println("Area of Rectangle: "+l*b); }
}
class Square extends Rectangle{ int side=5;
void areaOfSquare(){ areaOfRectangle(); System.out.println("Area of Square: "+(side*side)); }
}
class MultiLevelInheritanceExample{
public static void main(String args[]){ Square a=new Square(); a.areaOfSquare(); }
}
class Shape{ void area(){ System.out.println("Find area of rectangle and square:"); } } class Rectangle extends Shape{ int l=10,b=5; void areaOfRectangle(){ area(); System.out.println("Area of Rectangle: "+l*b); } } class Square extends Rectangle{ int side=5; void areaOfSquare(){ areaOfRectangle(); System.out.println("Area of Square: "+(side*side)); } } class MultiLevelInheritanceExample{ public static void main(String args[]){ Square a=new Square(); a.areaOfSquare(); } }
Ads