Give your classes real names rather than A and B and it will become obvious.
public class Animal … public class Dog extends Animal
If you now try to assign an Animal object to a Dog reference, how do you know the Animal is not a Cat?
Read about widening and narrowing reference conversions in the
Java Language Specification, but that can be difficult to read.