Overriding a method in Java is one of the main building block of writing object orientation code. In this tutorial we will learn the basic rules and test our knowledge with a quiz
Don't forget to take the quiz , you can go back and forth while reading
- Overriding is a runtime behavior , or runtime binding. The actual method call is decided at runtime.
- All abstract methods has to be implmented (or overriden) in the concrete subclass , failing do so is a compile time error. An abstract method need not to be overriden if the overrding class is abstract and the method abstract intendeded is also abstract.
Uninheritable methods can't be overriden
- final methods can't be overriden.Trying to override will lead to comiple time error (Cannot override the final method from <Class>)
- private methods can't be overriden. Trying to override will NOT lead to compile time error, since the method is not inherited the method seemingly overriding in the subclass is not overriding anything, but just a method belong to the subclass with no overriding property in it.
- static methods are not part of inheritance, so you can't override a static method. Trying to override will not lead to any compilation error. At runtime the reference type's method is invoked.
- TO BE CONTINUED
Don't forget to take the quiz , you can do back and forth while reading