+ 3
What is public static void
Can anyone explain this
4 odpowiedzi
+ 2
Public means that the method can be accessed from any other class
Static means that it can only be used by other static methods or classes (only one "copy" of this function exists)
Void means it doesnt return any value. A non-void value gets it's result stored in a variable, while a Void function does all output etc. from inside the function. An example is a function that prints out text
+ 2
Thomas static does mean that there only one copy exists, but it doesn't mean that you can use it only fro other static methods. For example you can create instance of class, and use static variable inside some of it methods.
https://code.sololearn.com/c4Fqh9DV1jM9/?ref=app
+ 1
Dima Makieiev Sorry, might have been a little vague. I was talking about functions because the question included void (only functions)
Here is the full explanation:
It is a method which belongs to the class and not to the object(instance)
A static method can access only static data. It can not access non-static data (instance variables)
A static method can call only other static methods and can not call a non-static method from it.
A static method can be accessed directly by the class name and doesn’t need any object
A static method cannot refer to "this" or "super" keywords in any way
I hope this is clear enough😁
+ 1
public means it is visible to all i.e., not only to that specific class in which it is declared but also in the other classes.
static means calling without instance variable. Eg. the main method which is called by jvm without any object.
void means the method which is declared as void is not returning any value.