Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Fresher-Trainee
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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


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


Advertisement
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  a java program to calculate the area of different shapes using Multilevel Inheritance
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
Advertisements
DATA Warehousing
DATA Warehousing       Position Vacant: DATA Warehousing (FRESHER/TRAINEE) Job Description...: DATA Warehousing (FRESHER/TRAINEE
 

 

 

DMCA.com