Implementation of methods in subclass that is already present in super class known as overriding
Conditions of method overloading:-
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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2lUSXmbCzWO3r6uXzsktz1JWMgO650tL2eggt1kCAiaCnSqgo9c3j6JqYgktvktAP1d4NDqTE4xxgOUXZ7TYRcx8Fe7l_pMO4BCeoDtUL4X7BCTkthVp-XY3yHsmJe89poFALNofM2Dk/s1600/9op.jpg)
Example 4 condition 4 not follows
Example condition 4 follows..
Conditions of method overloading:-
- Signature of the methods should be same present in sub class and in super class
- Return type of methods should be same in both classes.
- the access level of sub class method is equal to or greater than super class. click here.
- 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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2lUSXmbCzWO3r6uXzsktz1JWMgO650tL2eggt1kCAiaCnSqgo9c3j6JqYgktvktAP1d4NDqTE4xxgOUXZ7TYRcx8Fe7l_pMO4BCeoDtUL4X7BCTkthVp-XY3yHsmJe89poFALNofM2Dk/s1600/9op.jpg)
Example 4 condition 4 not follows
Example condition 4 follows..
No comments :
Post a Comment