+ 4
Is it necessary to set inner class as private??
I'm seeing no difference! can some one explain why?
5 ответов
+ 4
If it is not private you are ABLE to access, like this:
OuterClass.InnerClass innerObject = outerObject.new InnerClass();
+ 3
It's not necessary. If you want reach outside from the class you can referenced it Class.InnerClass.
+ 2
@Hari
I made a demo code for it:
https://code.sololearn.com/c226EEgRU7U6/#java
+ 1
Creating an inner class is simple, you just need to write a class within a class.
A class cannot be associated with the access modifier private.
Unlike a class, an inner class CAN be private and once you declare an inner class private, it cannot be accessed from an object outside the class.
- It is a way of logically grouping classes that are only used in one place;
- It increases encapsulation;
- It can lead to more readable and maintainable code.
0
even if it is not private I'm not able to access it!!
can we access the inner class from main? @gabor