February 2, 2011

Method Overriding and Overloading together in Java

A Java method can overridden and overloaded at the same time.


public class SuperClass {
   public void m1() {
      System.out.println("In SuperClass");
   }
}

public class SubClass extends SuperClass {
   public void m1() {
      System.out.println("In SubClass");
   }

   public void m1(int i) {
      System.out.println("Overloaded method in SubClass");
   }
}

No comments:

Post a Comment