posted 22 years ago
class Parent {}
class DerivedOne extends Parent {}
class DerivedTwo extends Parent {}
Which of the following statements is correct for the following expression?
Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
d2 = d1;
A. Illegal both at compile and runtime.
B. Legal at compile time, but may fail at runtime.
C. Legal at both compile and runtime.
The answer given is 'b' but according to me it is 'a'. Am I wrong?
Thanx
Sonali