Wednesday 28 August 2013

Method Overriding

Implementation of methods in subclass that is already present in super class known as overriding

Conditions of method overloading:-

  1. Signature of the methods should be same present in sub class and in super class
  2. Return type of methods should be same in both classes.
  3. the access level of sub class method is equal to or greater than super class. click here.
  4. static should be overrided to static and non static overrided  to non static.

Example 1-see condition 1 and 2 both follow



Example 2- see condition 3 not follow in this example



in the above example super class access level is protected and sub class method access level is default which is weaker in scope....
when condition 2 follows
                                               

Example 4 condition 4 not follows


Example condition 4 follows..

     





No comments :

Post a Comment