Public Visibility

suggest change

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


Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents