Different between private public in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Different between private public in java

java

16th Apr 2017, 2:51 PM
Sello Selby Bopape
Sello Selby Bopape - avatar
2 Answers
+ 2
There are 4 different access modifiers in Java. 1) public Visible to any class in any package. 2) private Visible only in the defining class 3) protected Visible in the defining class and all inherited classes 4) default Visible in the same package. Visibility means, that the variable or class can be seen or modified over the dot notation.
16th Apr 2017, 4:32 PM
Sven
Sven - avatar
+ 1
private cannot be accessed outside class and public can be accessed, is that the difference
16th Apr 2017, 2:52 PM
Sello Selby Bopape
Sello Selby Bopape - avatar