class A {
}
class B extends A {
}
class TestType {
public static void main(String args[]) {
A a = new B();
// I wish to use reference 'a' to check the Reference-Type which is 'A'.
}
}
Is is possible? If no, then please specif the reason.
If you call
a.getClass()then it will always return you instance of class from which this object was created. In your case it isBso it will return youB.class.Now if you want to call method on
aand get class asA.classthen you will not able to do it normal way.One way out would be define method in
Aand then you can call
a.getType()which isA.class. We are making use of static method here because they are not overridden.