Having obtained from A , you indicate that the instances of B are not only B , but also A This is called inheritance in OOP. The power of inheritance is to abstract common properties / behavior with a common class, and then derive specialized classes from it. Specialized classes can modify existing functionality (called overrides) or add new functions.
However, inheritance only works in one direction, not both. Class A objects cannot be thought of as B , because B can (and often does!) Contain more functionality than A Or, in other words, B more specific, while A is more general.
Therefore, you can do A a = new B(); , but not B b = new A();
source share