Class scoped variable means that only one instance of it will exist for that class. A class variable is known as a static variable.

public class foo{
    public static int a;
    public static void method(){
        System.out.println(a);
    }
}

foo.a = 5;
foo.method();
foo.a = 4;
foo.method();

Notice that no object has been created. The method which is called is also static. Static methods do not require a object to be created but they can only access other static methods or variables.

Seen static before? The main method is static! We do not create a instance of the class before main is called so it must be static.

next private modifier >>

 
Basics
Menu
Search