+ 1
Java related
what will happen if we use "private" instead of public in java
4 Antworten
+ 3
then you wont be able to access it outside of that class.
try that yourself
+ 2
Your internal class code can acces always to your internal code (class attributes and method), but what to code outside your class (at example code living in another class)?
public mean that also any code outside that your class can access to those method/attribute then dont matter where going referenced your public code. It can be referenced
private mean that only your class code can access to it and no others.
Exist also protected (that allow to access to it to derived class also) and package (specified without any specificator that allow to access to it to all classes belong to same package)
See here for details https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
+ 1
thanks
0
then what is the use if the owner is unable to access it