Tuesday, December 13, 2016

Write a JAVA program demonstrating the difference between method overloading and method overriding.

Write a JAVA program demonstrating the difference between method overloading and method overriding.

class Base
{
  void run()
  {
    System.out.println("Method from Base Class");
  }
}

class OverLoad extends Base
{
  void run()
  {
    System.out.println("Method from Derived Class");
  }
  void sum(int a,int b)
  {
     System.out.println(a+b);
  }
  void sum(double a,double b)
  {
     System.out.println(a+b);
  }
  public static void main(String args[])
  {
  OverLoad ovl=new OverLoad();
  ovl.sum(10.5,10.5);
  ovl.sum(20,20);
  ovl.run();
  Base b=new OverLoad();
  b.run();
  }
}


Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home