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.
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.