This can be possible when A
is a subclass of B
or we can say A
extends B
,
this is known as inheritance in programming language, in this A
will be a child of the class B
and inherit all its properties
you can check it from the link below
https://www.tutorialspoint.com/java/java_inheritance.htm