Public Visibility

Download java eBook

Example

Visible to the class, package, and subclass.

Let's see an example with the class Test.

public class Test{
    public int number = 2;

    public Test(){

    }
}

Now let's try to create an instance of the class. In this example, we can access number because it is public.

public class Other{
    
    public static void main(String[] args){
        Test t = new Test();
        System.out.println(t.number);
    }

}

Stats

Contributors: 1
2016-02-18
Licensed under: CC-BY-SA

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

Download eBook