Search code examples
javamodifiers

In java, about access modifiers, what the word "world" means?


I've seen here on stackoverflow a post where there was this simple and clear summary about access modifiers in java. I understand all but just one thing is weird :what the word "World" stands for ? What does it mean?

I have delete the display of the schema summary because the render was weird :s So please look at the link below >>>

Here is the link of the post: In Java, difference between default, public, protected, and private

Thks in advance!


Solution

  • It means if I have a class like:

    package com.example;
    
    public class Foo {
        public int bar;
    }
    

    I can access it from "outside" in the most general meaning of the word, like:

    package com.client;         // not in the same package of `Foo`
    
    class Client {              // not a subclass of `Foo`
        Foo foo = new Foo();    // possible because `Foo` is world-visible
        public int foobar() {
            return foo.bar;     // possible because `bar` is world-visible
        }
    }