Thomas SMETS
Posts: 307
Nickname: tsmets
Registered: Apr, 2002
|
|
Re: Question of the Day
|
Posted: Jul 31, 2002 5:01 PM
|
|
class P
{
static void printS1() // 2
{
System.out.print("P.printS1 ");
}
void printS2()
{
System.out.print("P.printS2 ");
}
void printS1S2 () // 1
{
printS1();
printS2();
}
}
class Q
extends P
{
static void printS1() // 2'
{
System.out.print("Q.printS1 ");
}
void printS2 ()
{
System.out.print("Q.printS2 ");
}
public static void main(String[] args)
{
new Q().printS1S2();
}
}
Suppose the code compiles, the thing is rather trivial. _ Invoking S1S2 on Q must invoke the method of the lowest layer (see 1); _ S1S2 invoke S1 (it's possible because S1 is defined on P), but 24 is invoked in fact (lowest level). _ Similar reasonning applies to S2. As we invoke the method from an instance of Q, there is no problem (neither a static overload by a member method).
IMHO the answer is therefore : "d", Prints: Q.printS1 Q.printS2
thomas,
|
|