+ 1
Hello World [Java Lesson]
After playing around with the “Hello World” code, I realized it won’t run unless you have Static, Public, AND Void. Why is this the case?
6 odpowiedzi
+ 1
You need all 3 at once because of the definition of each one. We need the function to be what each one of those do. We need the function to run without us creating an instance of the class so we use static. We need the function to be accessible from outside the class so we use public and the function returns nothing so we need void.
+ 1
Static: because you want to run the code without making a instance of the class.
Public: so everything can access it
Void: The method doesn't need to return a thing. The correct returntype for that is void.
0
I don’t know how to comment, but I know what each does, but why do I need all 3 at once?
0
Okay 😂
- 1
Public - anything outside the class can access the function
Static - doesn’t need an object to use
Void - doesn’t return anything
- 1
It’s what the Java creators decided to do