Reputation: 607
Suppose I have this hierarchy of classes
class Parent {
protected List<Object> things = new List<Object>;
public Parent() {
things.addAll(declareThings());
}
public List<Object> declareThings() {
// things declaration
}
}
class Child extends Parent {
public List<Object> declareThings() {
// additional things declaration
}
}
class GrandChild extends Child {
public List<Object> declarThings() {
// addtional things
}
}
I would like that creating an instance of say GrandChild, I get all the declared things
in the hierarchy. Is it possible to implement such behaviour?
Upvotes: 0
Views: 36
Reputation: 1808
For each subclass, add a constructor where the first instruction is super();
.
Upvotes: 2