Rules for method overriding
by, 04-26-2012 at 06:56 PM (8896 Views)
• Overridden method and argument list shall exactly be the same
• Return type shall be the subtype that is being declared in original method that is overridden in superclass, or it shall be the same.
• Restriction is not more in case of access level as compared to access level of the overridden method. E.g, when superclass is considerd to be public, in that case overriding method present in the subclass would not be public or private. But access level might not be much restrictive in comparison with access level of overridden method.
• If instance methods are inherited, by subclass, in that case only they might be overridden.
• Method which has been declared final might not get overridden.
• Method which has been declared static might be redeclared or not overridden
• Methods are not overridden if they are not inherited.
• Sublcass present in similar kind of package as that of instance superclass might be overridden to any method of superclass that has not been declared final or private.
• Subclass present in some other different package might override those methods which are declared protected or private.
• It is not possible to override constructors.