Fresher-Trainee

Fresher-Trainee

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 Tutorials/Questions & Answers:
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 { (adsbygoogle = window.adsbygoogle || []).push({}); public static
Fresher-Trainee
Fresher-Trainee  a java program to calculate the area of different shapes using Multilevel Inheritance
Advertisements
DATA Warehousing
DATA Warehousing       Position Vacant: DATA Warehousing (FRESHER/TRAINEE) Job... Warehousing (FRESHER/TRAINEE

Ads