Wednesday, January 8, 2020

Static Method Definition - Java

Normally you cant call a method of a class without first creating an instance of that class. By declaring a method using the static keyword, you can call it without first creating an object because it becomes a class method (i.e. a method that belongs to a class rather than an object). Static methods are used for methods that do not need to access to an objects state or only use static fields. For example, the main method is a static method: public static void main(String[] args) It is the starting point for a Java application and does not need to access an objects state. In fact, there arent any objects created at this point. Any parameters that it needs can be passed as a String array. To find out more about using the static keyword have a look at Static Fields.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.