What is the difference between static, public, and void?

“Static,” “public,” and “void” are all keywords in programming, typically associated with different concepts in various programming languages like Java, C++, C#, and more.

GENERAL

7/21/20241 min read

persons hand on black computer keyboard
persons hand on black computer keyboard

In Java (and many other object-oriented programming languages), static, public, and void are keywords that serve different purposes. Here's a breakdown of each:

“Static,” “public,” and “void” are all keywords in programming, typically associated with different concepts in various programming languages like Java, C++, C#, and more. Let’s break down the differences between these terms:

Static:
  • Purpose: The static keyword is used to indicate that a member (field or method) belongs to the class itself, rather than to any particular instance of the class.

  • Usage: When a method or variable is declared as static, it can be accessed without creating an instance of the class. Instead, it is called using the class name.

Example
Public:
  • Purpose: The public keyword is an access modifier that sets the visibility of a class, method, or field. A public member is accessible from any other class.

  • Usage: When a member is declared as public, it can be accessed from any other class in the program.

Example
Void
  • Purpose: The void keyword is used to specify that a method does not return any value.

  • Usage: When a method is declared with a void return type, it performs an operation but does not return any result.

Example