Overriding as overloading



Write a Program to
show that if parameters in the method overriding differ then method overriding
behaves as overloading.





class
A


 {


  double l,b;


  double CalArea(double x, double y)


    {


     l=x;


     b=y;


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


     return (l*b);


    }


 }


class
B extends A


 {


  double CalArea(float x, double y)


    {


     l=x;


     b=y;


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


     return (l*b);


    }


 }


class
Sk14


 {


  public static void main(String args[])


   {


    B obj=new B();


    double a1= obj.CalArea(5.5,6.5);


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


    double a2= obj.CalArea(7.5f,8.5);


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


    }


 }





Compile:


D:\>javac Sk14.java


Run:


D:\>java Sk14


Output:


Value
From Class A


Area=
35.75


Value
From Class B


Area=
63.75










0 Comments