Hi all,
what's the input for the following program? the answer is "The value is 2 The value is 3. I thought it should be "The value is 2 The value is 2". but when I ran it, it proved i was wrong. is it polymorpism? Can someone give me detailed explanation? I am really appreciated!
class Base {
int x=3;
public Base() {}
public void show() {
System.out.print(" The value is " + x);
}
}
class Derived extends Base {
int x=2;
public Derived() {}
public void show() {
System.out.print(" The value is " + x);
}
}
public class Test1 {
public static void main(
String args[]) {
Base b = new Derived();
b.show();
System.out.println("The value is " +b.x);
}
} // end of class
Test