inheritance
Posted: Mon Feb 24, 2014 3:50 am
Q-82 of 91 QId
If b2 = (B2)b1 won't compile as b1 can never refer to an object of class B2 then how can b1=(B1) b compile ??but it says that it will fail at runtime..although in both cases we are assigning a reference variable of base class to a reference variable of it's derived class.
Please explain..
Code: Select all
class B {}
class B1 extends B {}
class B2 extends B {}
public class ExtendsTest{
public static void main(String args[]){
B b = new B();
B1 b1 = new B1();
B2 b2 = new B2();
// insert statement here
}
}
Please explain..