Hello World [Java Lesson] | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 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.
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