Java Language Visibility (controlling access to members of a class) Public Visibility

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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

}


Got any Java Language Question?