Overloading vs Overriding
Overloading :
The Java programming language supports overloading methods, and Java can distinguish between methods with different method signatures. This means that methods within a class can have the same name if they have different parameter lists (by order of parameters, by type of parameters or by number of parameters)
Overriding :
An instance method in a subclass with the same signature (name, plus the number and the type of its parameters) and return type as an instance method in the superclass overrides the superclass's method.
The ability of a subclass to override a method allows a class to inherit from a superclass whose behavior is "close enough" and then to modify behavior as needed. The overriding method has the same name, number and type of parameters, and return type as the method that it overrides. An overriding method can also return a subtype of the type returned by the overridden method. This subtype is called a covariant return type.
in XYZ extends ABC scenario,
XYZ xyz = new ABC(); – not allowed
– Parent can hold his child and vice-versa is not true
ABC abc = new XYZ(); – Allowed
– you can access the overridden method
– you can access all superclass methods
– you can't access sub-class only methods