Dear all,
I ask myself about some of the rules governing the choice of variables or methods in inheritance.
1�) Is it correct to say that the same rules govern the choice of
instance variables and static methods during process of subclassing? I mean the choice of both of them depends on
the type of the reference at compile time?
And there's another rule governing the choice of
instance method, telling that this must be chosen depending on the
type of the object referenced at runtime So, the following code:
implies the following output:
B.s1 A.s2 A.s1 A.s2
B.m()
A.m()
x.s1 and x.m() call the instance variable and static method of B, whereas y.s1 and y.m() refere to to the instance variable and static method of A. It is the same logic in both cases.
Am I right here?
2�)question extracted from Dan's exam:
Response: H.printS1,null
Explanations:
The default constructor of H calls the constructor of G. The constructor of G calls the overridden method printS1 causing the invocation of H.printS1. The instance variable H.s1 hides G.s1. Although G.s1 has already been initialized, the initialization of the instance variables of H won't begin until the initialization and construction of G is complete.
I understand H.printS1, but definitly not the null.
Could someone give me light about this?
Thanks in advance for your response,
Cyril.