World's most popular travel blog for travel bloggers.

Explain use of static methods in java.

, , No Comments

 

  • A static method belongs to the class rather than the object of a class.
  • A static method can be accessed directly by the class name and doesn’t need any object.
  • A static method can access static data member and can change the value of it.
  • A static method cannot refer to "this" or "super" keywords in anyway.

In core Java program, execution starts from main method when you type java main-class-name, JVM search for public static void main(String args[ ]) method in that class and if it doesn't find that method it throws error NoSuchMethodError:main and terminates.

0 comments:

Post a Comment

Let us know your responses and feedback