Home Answers Viewqa Java-Beginners Fresher-Trainee

 
 


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

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

View Answers

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









Related Pages:
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
DATA Warehousing
DATA Warehousing       Position Vacant: DATA Warehousing (FRESHER/TRAINEE) Job Description...: DATA Warehousing (FRESHER/TRAINEE

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.