I have three classes:
class A
{
public Object Person;
}
class B extends A
{
}
class C
{
public String Name;
}
I want to access Name:
B b = new B();
C c = new C();
c.Name = "John";
b.Person = c;
String s = b.Person.Name; // This is not allowed. Name is not a property of Person.
How can I reference the Name property (for either writing to it or reading from it)?
In fact, I could have a class D, E, F that I need to assign b.Person where each class has completely different properties. So the solution needs to work with class D, E, F, etc.
You could considering use some Generics:
Or/And use some interfaces.
Anyway its a weird construction, you better just use a Person class where you can set the name. And in a object oriented way use some polymorphism.
I saw that you started a variable name with a capital letter, so a small tip: Use camel-casing (I fixed it in my example)