I have a class as follows.
public class MyClass{
public virtual class A{}
public class B extends A{}
public A someMethod(){
return new A();
}
public void myMethod(){
B b1 = (B)someMethod();
}
}
When executing myMethod()
, i got this runtime error:
Invalid conversion from runtime type MyClass.A to MyClass.B
I think as B is a child of A, instances of A can be cast to B.
Am I wrong? Why I got this error?