1. Use static keyword to declare a static class member in java.
  2. Declare static variable in a java class.
  3. Access static variable with the help of object and dot keyword.
  4. Access static variable with class name in a java program.

Static Keyword in JAVA video tutorial (Hindi)

Vineet Agrawal

Published on January 12, 2017
  1. Static keyword is used to declare a static class member in JAVA.
  2. Static class member is shared by all instances or objects of the class while all objects use a separate copy of a non-static class member.
  3. Static class members can also be accessed by class name.

class statickeyword
{
	int a=5; // instance member
	static int b=5; // static member
	public static void main(String args[])
	{
		statickeyword s1 = new statickeyword();
		statickeyword s2 = new statickeyword();
		System.out.println("s1.a++="+s1.a++);
		System.out.println("s2.a++="+s2.a++);
		System.out.println("s1.b++="+s1.b++);
		System.out.println("s2.b++="+s2.b++);
		System.out.println("statickeyword.b="+statickeyword.b);
		
	}
}
This content is part of the following course: 
Tags: 
Frequently Asked Questions
Required Components