PUB ID

Sunday, 28 February 2016

12 Rules of Overriding a Method in Java You Should Know

Rule #1: Only inherited methods can be overridden.
Rule #2: Final and static methods cannot be overridden.
Rule #3: The overriding method must have same argument list.
Rule #4: The overriding method must have same return type (or subtype).
Rule #5: The overriding method must not have more restrictive access modifier.
Rule #6: The overriding method must not throw new or broader checked exceptions.
Rule #7: Use the super keyword to invoke the overridden method from a subclass.
Rule #8: Constructors cannot be overridden.
Rule #9: Abstract methods must be overridden by the first concrete (non-abstract)          subclass
Rule #10: A static method in a subclass may hide another static one in a  superclass, and that’s        called hiding.
Rule #11: The synchronized modifier has no effect on the rules of overriding.
Rule #12: The strictfp modifier has no effect on the rules of overriding.

for more details with examples click here

No comments:

Post a Comment