So I've been trying to find the proper way to get what should be pretty straightforward inheritance to function (the way I want ;)) and I'm failing miserably. Consider this:
class Parent
{
public string name = "Parent";
public Parent() {};
public doStuff()
{
System.out.println(name);
}
}
class Child extends Parent
{
public string name = "Child";
public Child()
{
doStuff();
}
}
Please ignore any silly syntax errors as this is more of a conceptual question. I understand that Java doesn't do what I'd expect in this case as for some reason member variables aren't overridden the same way methods are but my question is what is the proper way to achieve the behavior I'd expect? I'd like my base class to contain some functions that operate on member variables provided/defined by a given subclass. I'd think get/sets could work, but then it destroys my ability to just call super() and have my base class do the construction needed making my subclasses contain a bunch of construction instead of isolating it to the base class.
Any constructive suggestions are welcome.