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
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
Example 4 condition 4 not follows
Example condition 4 follows..
No comments :
Post a Comment