This question was on the Jxam simulator:
What is displayed when the following piece of code is compiled and executed:
class Test{
public static void main(
String [] args){
Base b = new Subclass();
System.out.println(b.x);
System.out.println(b.method());
}
}
class Base{
int x = 2;
int method(){
return x;
}
}
class Subclass extends Base{
int x = 3;
int method(){
return x;
}
}
The output when executed is :
2
3
It explained that with the line: Base b = new Subclass();
calling varibles of b will come from the base class and methods will come from the Subclass?
This is hard to get a handle on. Any insite, or just memorize instead of rationalize?? Thanks
------------------