Can static variables be called using className.variableName in Java?

Java 8Object Oriented ProgrammingProgramming

Class variables also known as static variables are declared with the static keyword There would only be one copy of each class variable per class, regardless of how many objects are created from it. You can access a class variable without instantiation using the class name as className.variableName.

Example

Live Demo

public class Test{
   static int num = 92;
   
   public static void main(String args[]) throws Exception {
      System.out.println(Test.num);
   }
}

Output

92
raja
Published on 10-Jan-2018 06:23:21
Advertisements