0

Need help java newbie question

why does this code still prints "helloworld" when there is a word void before the sayHello() method?(i thought void means that it will not return anything?) class MyClass { static void sayHello() { System.out.println("Hello World!"); } public static void main(String[ ] args) { sayHello(); } } // Outputs "Hello World!"

14th Oct 2017, 9:16 PM
oyl
2 Respuestas
+ 2
think of it like this... static void Hello(){System.out.println("Hello World!"); main// Hello(); //output "Hello World" //is very similar to static String x = "Hello World!"; //main System.out.println(x); // output "Hello World!" void is a return type it dosent return a string or an int it returns nothing when you call it its only printing hello world because the println method is attached to it..
14th Oct 2017, 10:19 PM
D_Stark
D_Stark - avatar
0
It doesn't return anything. The words "Hello, World" are simply printed to the screen, and no value is returned to the main method after the sayHello() method is called.
14th Oct 2017, 9:32 PM
DaemonThread
DaemonThread - avatar