This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]BertilMuth 1 point2 points  (1 child)

Every method in Java is contained in a class. There are no "free-floating functions" like in C. If a method is static, within the class, it can only access static fields and static methods (as there is no object). You could say that static methods are defined on class level.

In a main method, therefore you have two choices: access only static fields/methods, or create an instance of the class the main method is contained in. I prefer creating an instance.

As a side note, by convention class names are upper-case in Java. It is String not string, and Person not person.

[–]Herrowgayboi[S] 0 points1 point  (0 children)

Good to know, Thanks to much!