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

6th May 2018, 3:15 PM
Avontae Jones
Avontae Jones - avatar
6 Answers
+ 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.
6th May 2018, 3:42 PM
cyk
cyk - avatar
+ 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.
6th May 2018, 3:24 PM
***
*** - avatar
0
I don’t know how to comment, but I know what each does, but why do I need all 3 at once?
6th May 2018, 3:27 PM
Avontae Jones
Avontae Jones - avatar
0
Okay 😂
6th May 2018, 3:29 PM
Avontae Jones
Avontae Jones - avatar
- 1
Public - anything outside the class can access the function Static - doesn’t need an object to use Void - doesn’t return anything
6th May 2018, 3:25 PM
TurtleShell
TurtleShell - avatar
- 1
It’s what the Java creators decided to do
6th May 2018, 3:28 PM
TurtleShell
TurtleShell - avatar