Method Overriding



Write a Program to
implement the concept of method overriding.





Program:


class
A


 {


  protected double l,b;





  A(double x,double y)


   {


    l=x;


    b=y;


   }


  double CalArea()


    {


     System.out.println("Class A");


     return (l*b);


    }


 }


class
B extends A


 {


  B(double x,double y)


   {


    super(x,y);


   }


  double CalArea()


    {


     System.out.println("Class B");


     return (l*b);


    }


 }


class
Sk13


 {


  public static void main(String args[])


   {


    B obj=new B(5.5,6.5);


    double a= obj.CalArea();


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


   }


 }


Compile:


D:\>javac Sk13.java


Run:


D:\>java Sk13


Output:


Class B




Area= 35.75


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