Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Call Static Variables Using Class Name in Java



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
Updated on: 2019-07-30T22:30:20+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements