I wasn't quite sure how to word it in the title, but here is the use case.
I have a class Test. Test has an attribute called Letter as so
public class Test() {
Letter x;
}
Letter can be one of several subclasses.
class A()
class B()
class C()
Now suppose that in a class (let's call it driver), I have an instance of Test. I want to figure out whether this Test's letter is A, B, C, etc. so that I can access attribute unique to the child class. See:
public class Driver() {
Test t;
}
If I use t.getClass(), will I get Class.Test, or will I get the child class (e.g. Class.A)? Is it possible for the Driver class to know x's subclass?
Is it possible to create a method like:
public Class getSubclassFromLetter(Letter x) {
// Find subclass from the letter
}