[CODE]
class Trebble{
int i = 99;
}
class Base extends Trebble{
int i =100;
}
public class Central extends Base{
public static void main(String argv[]){
Central c = new Central();
c.wynyard();
}
public void wynyard(){
Trebble t = new Central();
Base b = (Base) t;
System.out.println(b.i);
}
}
[/CODE}
1 Compile time error
2 Compilation and output of 99
3 Compilation and output of 100
4 Compilation, but runtime error because an instance of Trebble cannot be cast to type Base
The Correct Answer is 3).This is on what basis?
class Trebble{
int i = 99;
}
class Base extends Trebble{
int i =100;
}
public class Central extends Base{
public static void main(String argv[]){
Central c = new Central();
c.wynyard();
}
public void wynyard(){
Trebble t = new Central();
Base b = (Base) t;
System.out.println(b.i);
}
}
[/CODE}
1 Compile time error
2 Compilation and output of 99
3 Compilation and output of 100
4 Compilation, but runtime error because an instance of Trebble cannot be cast to type Base
The Correct Answer is 3).This is on what basis?