In the following discussion, A and B are used. Type A extends type B (type means class or interface).
Field
Only hiding applies tojava fields. Hiding happens in the following situation.Both A and B have a variable named as var. And var is of the same kind of variables ( static fields or instance fields).
Java allows a variable belonging to different variable kinds appears in both A and B. But hiding does not happen in such situations.
Method
Method m1 in A . Method m2 in B.
- m1 is subsignature of m2
- m1's visibility is no less than m2
- Both m1 and m2 are instance methods. Or both m1 and m2 are static methods. Otherwise, there will some compile errors.
Overriding
Overriding applies to instance methods.
Hiding
Overriding applies to static methods.
No comments:
Post a Comment