Overriding
Override the implementation. The method has the same signature i.e. name and same parameters. Used for polymorphmism (multiple forms). This is achieved using inheritance.
interface IHuman {
public void entertainYourSelf();
}
class Papa implements IHuman {
public void entertainYourSelf() {
System.out.println("I play at the park");
}
}
class Son extends Papa {
public void entertainYourSelf() {
System.out.println("I play on my smartphone");
}
}
public class Polymorphism {
public static void main(String[] args) {
IHuman papa = new Papa();
papa.entertainYourSelf();
IHuman son = new Son();
son.entertainYourSelf();
}
}
Overloading
Overload the implementation. The method has the same name but different parameters. In C++ world this was called static polymorphism. Overloading generally happens in the same class.