In the context of inheritance, when B
is subclass of A
, an instance of B
can be used anywhere where an instance of A
is valid. This is the characteristic of polymorphism. However I have a question.
I know it's correct:
A oa = new A();
B ob = new B();
A oab = new B();
However, is this also correct?
B oba = new A();
And if it is, I'd like to know why.