Pregunta

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!

¿Fue útil?

Solución

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
    }
}

Otros consejos

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

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top