Next SCJP candidate please...

V

VisionSet

Here's a nice easy question for you:

class Base {

void methodB(Base b) {
System.out.println("Base");
}

void methodA(Base b) {
methodB(b);
}
}

class Derived extends Base {

void methodB(Derived d) {
System.out.println("Derived");
}
}

public class Test {

public static void main(String[] args) {

Derived x = new Derived();

x.methodA(new Derived());
}
}

What gets printed out?

<spoiler>
The possible confusion, that I'm ashamed to admit got me for a bit, is since
methodB is called with what is class Derived, one may think that
Derived.methodB(Derived d) would be called.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top