I have a class, called Building, and there are several classes that extend it, for example, Office and Hospital. The extending classes add at most, only a dozen or so lines of code, thus I would not like to put them in different files. I don’t believe inner classes will work since it requires an instance of the outer class first -> Building.
Thus, what I want to do is do Building b = new Office(var);, but not have Office code in Office.java since it will contain at most a few lines of code, but Building will have most of the code. But having Office as the type is valuable in my situation. Any help? Thank you for your time!
You could use a static nested class, then you wouldn’t need an instance of Building, but I think in this case the best thing would be to use separate Java files. It doesn’t matter if they only contain a few lines.