I have a abstract Parent class that has multiple children. I'd like the child to be able to have a variable that is the same for every instance of that child. I'd prefer not to pass a constructor to the child to tell it it's name because that just seems silly when it can be hardcoded. From what I've read doing the following "hides" the parents instance variable and doesn't work as I want.
public abstract class Parent {
public String name = "the parent";
public getName(name);
}
public class Child1 extends Parent {
public String name = "Jon";
}
public class Child2 extends Parent {
public String name = "Mary";
}
Child1 c = new Child1();
c.getName(); // want this to return "Jon", but instead returns "the parent".
To be clear, basically what I want is something like c.getClass().getName() but I don't want to have the result of that dependent on the Class name, but rather on a hardcoded value.
Thanks