Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)
What does public static void mean in Java?

I'm in the process of learning. In all the examples in the book I'm working from public static void comes before any method that is being used or created. What does this mean?

3 Answers

0 votes
by (46k points)

It's three completely different things:

public means that the method is visible and can be called from other objects of other types. Other alternatives are private, protected, package and package-private. See here for more details.

static means that the method is associated with the class, not a specific instance (object) of that class. This means that you can call a static method without creating an object of the class.

void means that the method has no return value. If the method returned an int you would write int instead of void.

The combination of all three of these is most commonly seen on the main method which most tutorials will include.

0 votes
by (37.3k points)

These are three different components:

public is the access specifier that indicates the method is visible and can be called from objects of other types outside the class. Other alternative access specifiers are private and protected.

static means that the method is associated with the class, not with any instance (object) of that class. This indicates that you can call a static method without creating any object of the class.

void It indicates the type of value returned from a method and here it returns no value.

The combination of all three of these is mostly seen in the main method.

0 votes
by (2.8k points)

The three words completely hold  different meanings:
public means that the function is visible and can be called from other objects of different types. Other substitutes can be private, protected, package and package-private.
static means that the method is related with the class, and not a specific object of that class. This means that you can call a static function without creating any object of the class.
void indicates that the function will have no return value. If the method returned an integer you would have to write int instead of void.
The integration  of all three of these is most commonly seen in the main function

Related questions

0 votes
1 answer
asked Nov 25, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
asked Oct 27, 2019 in Java by Shubham (3.9k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...