I have a class Super and several subclases Sub1, Sub2,…
Is there a way to instantiate objects sub1, sub2 that would share the same super instance?
The situation comes from an inner nested class configuration like this:
Super{
superFields...
Sub1{...}
Sub2{...}
........
}
But the inner claeses have grown too much, and I woud feel more confortable having them in separate files. They need to share the same instance of superFields, so my question.
Inner classes are implemented by having the superclass as argument of all their constructors.
So that’s what you can do as well:
and whenever you want to instantiate the subclass from within the superclass: