+ 1
What is the difference between public,private,protected and default access modifiers in classes in java?
if I do private static class Apple{},then the apple class cannot be accessed by the main java class??
3 ответов
+ 2
These access modiiers prevent other classes from using the data in any way they want. For example, you can make a variable private so that another class inheriting the other class can't just manually change the variable. So instead your main class that has the private variable can have a function to set the variable but it'll go through filtering before being set. This is just an example, you can't do much more..