Question: The result of the following code is "5 A" and "10 B". How is it possible that for b.print(), this.num is a reference to a Class A object and this.getClass() is a reference to a Class B Object?
Superclass A
public class A {
private int num;
public A(int num) {
this.num = num;
}
public void print() {
System.out.println(this.num + " " + this.getClass().getName());
}
}
Subclass B
public class B extends A {
public B(int num) {
super(num);
}
}
Main Method
A a = new A(5);
B b = new B(10);
a.print();
b.print();