What does the 'static' keyword ? what it do in a class?

what is the use of the static keyword in class why dot we access the instance variables through static instance


public class Clock
public void setTime()


public class Hello {

Clock clock = new Clock();

public static void main(String args[]) 


in above program if we call the clock.setTime() method then that generates error like non-static method setTime() cannot be referenced from a static context.
if we write static keyword before Clock class it si working why…please help me…

static Clock clock = new Clock();

static members belong to the class instead of a specific instance.

It means that only one instance of a static field exists even if you create a million instances of the class or you don't create any. It will be shared by all instances.


Since static methods also do not belong to a specific instance, they can't refer to instance members, static members can only refer to static members. Instance members can, of course access static members.