Interface members

Download java eBook

Example

public interface MyInterface {
    public void foo();
    int bar();

    public String TEXT = "Hello";
    int ANSWER = 42;

    public class X {
    }

    class Y {
    }
}

Interface members always have public visibility, even if the public keyword is omitted. So both foo(), bar(), TEXT, ANSWER, X, and Y have public visibility. However, access may still be limited by the containing interface - since MyInterface has public visibility, its members may be accessed from anywhere, but if MyInterface had had package visibility, its members would only have been accessible from within the same package.

Stats

Contributors: 2
2016-08-15
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook