Hi Harwinder!
Thanks!
I got it now! The difference is that in the first example the methods are been
overriden, and on the second they're been
overloaded!! I just noticed that now! DUH!!!
Now the explanation is: the methods that are been overloaded are totally different methods. So if you have an A reference, the ONLY method you got is void m1(A a)! The others are been defined on the other classes that extend the A class.
When you create an object and assign it to a superclass reference type (eg.: A c1 = new C()
then you're saying to the compiler "create an object of type C, but assign it to a reference that gives me only the interface found on the A class declaration".
In runtime, Java knows that the c1 reference of type A is actually an object of type C, but you'll only have access to the methods found on A declaration. You can get access to the other methods found on C class by making a explicit cast like this: ((C)c1).m1
I hope you got it now. Thanks anyway!!
[ October 29, 2003: Message edited by: bengt hammarlund ]
[ October 29, 2003: Message edited by: bengt hammarlund ]