When to use inner classes in Java for helper classes

Yes, it makes perfect sense to make it an inner class. If no other classes need it, make it private. If it doesn’t require exclusive access to the members of the outer class, make it a static nested class because then it will require less memory space.

Check out the recommendation from the official tutorial –

Use a non-static nested class (or inner class) if you require access
to an enclosing instance’s non-public fields and methods. Use a static
nested class if you don’t require this access.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)