given the following code, I have a question:
class A{}
class B extends A {}
class C extends B{}
public class Test {
public static void main(String[] args) {
In your code example, the variable a
is a reference to an object of type A.
The class B extends the class B,
but the relationship between classes A and B can only be described as follows:
This is legal: a = (A)b;
because class B isa class A.
One way to think of it is class B is a superset of class A.
If A is a set that contains (1, 2) and B is a set that contains (1, 2, 3) then B is a superset of A (in java terms: B can be cast to A) but A is not a superset of B (A can not be cast to B).
From a different point of view:
Socrates (class B) isa man (class A).
This is an invalid minor assertion: All men are Socrates.