Hi ALL!I am a little bit confused over object reference casting.Help me out guys ,my deadline is approaching!
class A {
void method(){
System.out.println(" in A");
}
}
class B extends A {
void method(){
System.out.println(" in B");
}
}
class C extends B {
void method(){
System.out.println(" in C");
}
}
public class MyClass{
public static void main(
String args[]){
A a=new C();
B b=(B)a;
b.method();//prints "in C" no problem here
C c=new C();
b=c;// shouldn't this give me a compiler or runtime error??
if(b instanceof C)
System.out.println("true");// this prints true why?
}
}
Do let me know.
Thanks all,
Vedhas.