extends
is used for inheritance and in layman term it resembles “is-a” property
So class A which extends some other class B, means that “Class A is-a Class B”.
And in other words Class B is a Parent of Class A.
Parent class reference can hold a child object but vice-versa is not possible.
Cell c = new BloodCell(); // OK, as BloodCell is a Cell,
Cell c = new RedBloodCell(); // OK, RedBloodCell is a Cell
BloodCell c = new RedBloodCell(); // OK, RedBloodCell is a BloodCell
RedBloodCell c = new BloodCell(); // ERROR, BloodCell is not a RedBloodCell
1
solved Understanding assignments and “extends” in Java