Interesting

Static Method

Static Method


We are searching data for your request:

Forums and discussions:
Manuals and reference books:
Data from registers:
Wait the end of the search in all databases.
Upon completion, a link will appear to access the found materials.

Normally you can't call a method of a class without first creating an instance of that class. By declaring a method using thestatickeyword, 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 object's 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 object's state. In fact, there aren't any objects created at this point. Any parameters that it needs can be passed as aStringarray.

To find out more about using thestatickeyword have a look at Static Fields.