Method overriding:
Redefining parent class method and implementing in our own way is known as method overriding. In the method, overriding method name and signature must be same.
The main usage of method overriding we can achieve runtime polymorphism. In the method, overriding method name must be same and arguments (or) parameters must be in order. We can’t override static, final methods because static methods are allocated memory at compile time only but by using we are achieving run time polymorphism.
Rules for method overriding:
· The method name and arguments must be same and within the order only.
· We can’t change return type.
· Only child classes can override parent class methods.
· Static , final methods can’t be overridden.
· Constructor can’t be overridden.
Differnces between overriding and overloading
EmoticonEmoticon