Tag Archives: access modifiers

Access Levels in Java

Most people confused with the access modifiers in java so lets talk little bit about it. The confusing part is “private” and “not defined modifier” as an example if declared the two variables with in the class as follows then where I can access those

private int can_see_for_class;
int can_see_with_in_package;  

Java by default it has been assigned the package private that means you can access your variable with in the same package.

Access Levels
Modifier Class Package Subclass World
public Y Y Y Y
protected Y Y Y N
no modifier Y Y N N
private Y N N N

Private : Like you’d think, only the class in which it is declared can see it.
Package Private : Can only be seen and used by the package in which it was declared.
Protected : Package Private + can be seen by subclasses or package member.
Public : Everyone can see it.

1 Comment

Posted by on June 8, 2014 in java


Tags: , ,

%d bloggers like this: