qaz
qaz

Reputation: 109

What is the "world" access level in a java program?

Access Levels
Modifier        Class   Package Subclass    World
public            Y       Y       Y          Y
protected         Y       Y       Y          N
(Default)         Y       Y       N          N
private           Y       N       N          N

what is the "World" access level? How is it different from the package access level?

EDIT: MY BAD. Had fallacy that all code in a program is in a single package.

Upvotes: 2

Views: 794

Answers (2)

Ayush
Ayush

Reputation: 85

public is the most wider access level in java.There's no restriction on either accessing attributes or inheriting the class members.They are visible in all package.So,eventually there's nothing like world modifier rather it might be just a synonym to define public.

Upvotes: 1

MarsAtomic
MarsAtomic

Reputation: 10696

This comes directly from the Java Tutorial:

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

The first data column indicates whether the class itself has access to the member defined by the access level. As you can see, a class always has access to its own members. The second column indicates whether classes in the same package as the class (regardless of their parentage) have access to the member. The third column indicates whether subclasses of the class declared outside this package have access to the member. The fourth column indicates whether all classes have access to the member.

The scope of "world" is literally "everything" -- any class, regardless of the package to which it belongs, can access a class declared with the public access modifier.

Contrast this with protected, which means that classes within the package and subclasses of the protected class regardless of package can access the class.

Upvotes: 5

Related Questions