C:\Java\EigeneJavaProgramme>
java Q028a
A(): i= 1
B(): i= 2
Q028a(): i= 2
A(): i= 3
Q28a:get()
7
A
nlyA()
In Q028a class Q028a overrides the get() method of class B.
At first a Q028a instance is created which results in the call of the superclass
Constructors A() and B(). Then i is incremented from 0 to 2.
Then an A instance is created and „A(): i= 3“ is printed.
Afterwards the Q028a instance is transformed to an A instance. It still retains
The object type of Q028 but gets A as Referencetype.
Therefore it calls Q28a.get() method because it is overridden and increments
Variable i to 7. The Object type (Q028a) is responsible for overridden methods
So it calls the get() method of class Q028a.
Then it invokes onlyA(). This method is not overridden in Q028a so the Reference-
Type counts for the method invocation and „onlyA()“ from class A is invoked.
Now consider this case Q028:
Here Q028 has no own get() method.
MY QUESTION IS:
WHY does it invoke the get() method of superclass B and not the get() method
Of A because obj is of Reference type A when it invokes obj.get()???
C:\Java\EigeneJavaProgramme>java Q028
A(): i= 1
B(): i= 2
Q028(): i= 2
A(): i= 3
B:get()
6
A:onlyA()
(edited by Cindy to disable smilies)
[ November 21, 2002: Message edited by: Cindy Glass ]