Override

Categories: Java // Tags: , , .
Email this to someonePrint this pageShare on Google+0Share on Facebook1Tweet about this on TwitterShare on LinkedIn2Share on Reddit0Pin on Pinterest100Share on StumbleUpon1


Override
Class inheriting the method from its super class has the option to override it. Benefit of overriding is the ability to define behaviour specific to particular class.

Method Overriding Example

Method Override Rules

  • Overriding method can not have more restrictive access modifier than the method being overriden but it can be less.
    The argument list must exactly match that of the overriden method, if they don’t it is more likely that you are overloading the method.
  • Return type must be the same as, or subtype of the return type declared in overriden method in Super class.
  • Overriding method can throw any unchecked exception(Runtime) but it can throw checked exception which is broader or new than those declared by the overriden method but it can not throw fewer or narrow checked exception.
  • Final method can not be overriden.
  • Static methods can not be overriden.
  • If a method cannot be inherited then it cannot be overriden.

Email this to someonePrint this pageShare on Google+0Share on Facebook1Tweet about this on TwitterShare on LinkedIn2Share on Reddit0Pin on Pinterest100Share on StumbleUpon1

About Team

Browse Archived Articles by Team