+ 1

Java related

what will happen if we use "private" instead of public in java

5th Jun 2018, 11:11 AM
G V JAGANNATH
G V JAGANNATH - avatar
4 ответов
+ 3
then you wont be able to access it outside of that class. try that yourself
5th Jun 2018, 11:12 AM
shobhit
shobhit - avatar
+ 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
5th Jun 2018, 11:30 AM
KrOW
KrOW - avatar
+ 1
thanks
5th Jun 2018, 11:31 AM
G V JAGANNATH
G V JAGANNATH - avatar
0
then what is the use if the owner is unable to access it
5th Jun 2018, 11:14 AM
G V JAGANNATH
G V JAGANNATH - avatar