Email address:
Password:
SCJP/OCPJP 1.6 certification
Practice Exams and Training
SCJP Online Training » Discussions

What is the real world usage of abstract private inner classes?

Hi Frederick!

Btw, what is the practical purpose of inner abstract private classes?


Thank you!

Good question!


Generally, it has the same purpose of why you would need non-abstract private inner classes.


You would want to add a private inner classes when you realize you need a helper class that would only be used within the methods of your regular class. In other words, when you realize you need a class that doesn't make sense without the presence of another class you are working on, you would want to make sure the new class you are going to add will be tightly and privately coupled with the class you are working on. A private inner class is the best way to go when you want to address that.


In the same way, when you want polymorphic behavior with an abstract base class, but yet shared only within the scope of a regular class, a private abstract class would come in handy for that.


But I must state that this is an extremely rare use case, which would lead to a way too complicated design.


Thank you for the detailed explanation!

ExamLab © 2008 - 2024