Wednesday, February 27, 2013

difference between static method and instance method in Java

Static Method:
===========
1.A method i.e. declared as static is known as static method.
2.Object is not required to call static method.
3.Non-static (instance) members cannot be accessed in static context (static method, static block and static nested class) directly.
4.For example: public static void show(){..... }.


Instance Method:
============
1.A method i.e. not declared as static is known as instance method.
2.Object is required to call instance methods.
3.static and non-static variables both can be accessed in instance methods.
4.For example: public void show(){...}.


 

No comments:

Post a Comment