# Fresher-Trainee

nisha
Fresher-Trainee
2 Answer(s)      6 years and 7 months ago
Posted in : Java Beginners

a java program to calculate the area of different shapes using Multilevel Inheritance

March 29, 2011 at 3:52 PM

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();
}
```

}

March 29, 2011 at 3:55 PM

```  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();
}
}
```

Fresher-Trainee
Fresher-Trainee  the below pgm has an exception during run time, and has no errors during compilation , pls help. wat to do? class Pyramid { public static void main(String[] args) { int x = 9; for (int i
Fresher-Trainee
Fresher-Trainee  a java program to calculate the area of different shapes using Multilevel Inheritance