RSS

Access Levels in Java

08 Jun

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.

Advertisements
 
1 Comment

Posted by on June 8, 2014 in java

 

Tags: , ,

One response to “Access Levels in Java

  1. for ibs

    September 26, 2014 at 7:39 pm

    My brother recommended I might like this blog.

    He was entirely right. This post truly made my day.

    You cann’t imagine simply how much time I had spent for this information! Thanks!

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: