Originally posted by prasanna sheregar:
Overriding happens only when we talk about inherited classes is it?
Correct.
A method is being overridden if:
- the return type and parameters are exactly the same*
- the method exists in a parent class (doesn't have to be the direct parent)
- the method that is overridden is not private or static.
I've added the last line because you cannot override a private or static method - you reimplement them, hiding the method in the parent class.
* Actually, the return type can be narrower since
Java 5. This is called "covariant return".
Now, overloading can only be done within the same class, so neither example is overloading.