+ 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 Respostas
+ 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