What does public static void mean?

 

So what does Public Static Void mean, exactly? It's one of those groups of modifiers you get really good at typing in introductory programming assignments. It's also the most popular search term used by people finding this blog post. For their benefit, let's go over what these three popular words mean.

Public is an access modifier. If you're the only one writing and maintaining your code, there's no real reason to use any setting other than public. However, you still need to explicitly write it out, or your variables and methods will be initialized using the default access rules. Besides using public and no modifier at all, you can also use the private and protected modifiers.

Static is another access modifier; it essentially states whether you'll be using the variable, method or class in a standard or object-oriented manner.

Void indicates the return type of the method; a method with a void return type does not return any value.

When you're writing the main() method for a command-line application, you'll use the syntax public static void main( ... ) because:

* It's the first function the system calls when it executes the application, so it must be public
* You're not instantiating an object, you're running the function directly so it must be static
* No value is returned to the command line, so it should be void

Confused yet? Good, welcome to programming!

1 Comment

Did you enjoy this post? Please spread the word.