2

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!

Community
  • 1
  • 1
user2305415
  • 172
  • 1
  • 3
  • 18

3 Answers3

1

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
    }
}
Santa
  • 11,381
  • 8
  • 51
  • 64
  • Okey, thank you i understand better, but how do you know it is"world-visible" ? since i can't see the word "world", but maybe i think that by default, if i don't specify, then the class method or variable would implicitely be "world-visible" ? – user2305415 Apr 27 '13 at 21:26
  • It's because of the keyword `public`. The default is actually package-visible. – Santa Apr 29 '13 at 20:24
0

"World" is the visibility description when using non-reflection references from outside the package, as in a library reference.

Tetsujin no Oni
  • 7,300
  • 2
  • 29
  • 46
0

World means you can call that method, or access that field or class no matter where the code is written, no matter the packaging, subclass, and so forth.

It could even be "universe" if you prefer.

durron597
  • 31,968
  • 17
  • 99
  • 158
  • Thks, understand better the concept now. – user2305415 Apr 27 '13 at 21:27
  • @HotLicks You could if you had an instantaneous communication layer (ICL) with an asynchronous socket protocol. Don't leave home without one. – durron597 Apr 30 '13 at 21:46
  • The problem is that Beta Tauri 5 uses a base pi numbering system. They have most of the translation worked out, but they frustratingly can't translate `1`, and `1` is the value of the `public` modifier. – Hot Licks Apr 30 '13 at 22:12