Multi Level Inheritance



Write a program in Java to implement multi level Inheritance


Program:


class
Rectangle


 {


  double l,b;


  Rectangle(double x,double y)


   {


    l=x;


    b=y;


   }


  double CalArea()


    {


     return (l*b);


    }


 }


class Box
extends Rectangle


 {


  double h;


  Box(double x,double y,double z)


   {


    super(x,y);


    h=z;


   }


  double CalVol()


    {


     return (l*b*h);


    } 


 }


class
Cube extends Box


{


  Cube(double s)


    {


      super(s,s,s);


    }


}


class
Sk11


 {


  public static void main(String args[])


   {


    Cube obj1=new Cube(5.5);


    double a1= obj1.CalArea();


    double v1= obj1.CalVol();


    System.out.println("Area= "+a1);


    System.out.println("Vol= "+v1);


    }


 }


Compile:


D:\>javac
Sk11.java


Run:




D:\>java
Sk11


Output:


Area =
35.75


Volume =
268.125


















Comments

Popular posts from this blog

Write a Program to Add two 3x3 Matrix using C

C program for Unit Conversion

Write a Program to Add two 5x5 Matrix using C