package pack1;public class TestSupSub{public static void main(String []args){SuperClass s= new SubClass();s.disp();}};
Hmmmm...I got your point...
ok..In your Test class while you are calling s.disp();, it means...your compiler is dreaming that you are calling SuperClass's method (it is called runtime polymorphism), So it does not warn you...but actually at runtime you will get subclass's method call...
Now if you do like new SubClass().disp() your compiler will warn you that it is not visible to it. as you know that protected method it not visible to other classes unless extended....
protected method of a class to which it is not related through inheritance
[My Blog]
All roads lead to JavaRanch
Originally posted by Ashutosh Limaye:
Point 3: There is no relation between TestSupSub and SubClass (ie. Inheritance)
Jitendra
SCJP1.5
SCWCD1.5
Consider Paul's rocket mass heater. |