I have an abstract class MotherClass and two abstract classes ChildClass1 and ChildClass2 that extend MotherClass.
I wish to make sure that any class extending MotherClass will in fact extend ChildClass1 or ChildClass2. I feel that something is wrong in my tree-based class design. Do you see how to make it properly?
If
MotherClasshas package visibility andChildClass1andChildClass2are public and in the same package, you could subclass those two but not MotherClass.Edit:
Another possibility:
Method:
You now couldn’t do
This would compile but give you a warning at least:
Ways without warning: