When to use inner classes in Java for helper classes

后端 未结 11 2096
醉梦人生
醉梦人生 2020-12-04 07:24

If I have for example a class along with a helper class to do some of its functionality, does it make sense to make it as an inner class.

    public class F         


        
11条回答
  •  北海茫月
    2020-12-04 07:41

    Yes, the advantage of using inner class is it can access members of outer class.In your case , if you think your FooHelper is not to be used by any other class,you can make it a inner class.

    To check out the utility of inner class, go through the examples of AWT. Anonymous inner classes are widely used in event handlers.

提交回复
热议问题