Access level | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Access level

I still don’t know what access level is in Java(like public private...) can someone help me Thanks in advance

27th Apr 2020, 11:49 AM
Zhengrong Yan
Zhengrong Yan - avatar
3 Answers
+ 3
David Yan let me give it a shot. public -> something that is open to all. This access modifier when applied to class or a method than it can be even accessed inside some other class in the same package or in a different package as well. private -> something that is not open at all. This access modifier when applied to a class is pretty useless but when applied to a method then it makes the method inaccessible to any other class. You cannot call it from outside the class in which it is declared. protected -> something that is neither completely private or completely public. This access modifier when applied to a method, can be accessed by other classes inside the same package and can also be accessed by classes from a different package but 'only through inheritance'. These might be slightly difficult to understand at first but once you start using it in your code then you will get to know them better.
27th Apr 2020, 12:54 PM
Avinesh
Avinesh - avatar
0
Access Modifiers control how much of an object is visible to the rest of Java program, and packages provide the highest level of control over object visibility. For ex: a class that is not public is not visible outside its own package. There are 4 different access modifiers available in java language. They are public, protected, private and no modifier (declaring without an access modifier). Using ‘no modifier’ is also sometimes referred as ‘package-private’ or ‘default’ or ‘friendly’ access. http://net-informations.com/java/basics/modifiers.htm
18th May 2021, 6:44 AM
linehammer