Top News

What is the difference between static method and instance method in Java?

Often, there is a need to define a behavior for a class that is not
dependent on member variables of an object. Such behavior is
captured in a static method.

If there is a behavior dependent upon
the member variables of an object, then we do not mark it static, it
remains as instance method.

To call as static method, we do not need to create an object. We just
call it with class name. But to call an instance method, we need to
create/get an object first.

Instance member variables cannot be accessed by a static method.
But an instance method can call both instance variables and static
variables. 

Post a Comment

Previous Post Next Post