0

Beginner java question(still learning)

why does this code not printing helloworld? (sorry im a real beginner,please forgive me if my code looks idiotic.im trying to play around with the code) class MyClass { static void sayHello() { System.out.println("Hello World!"); } public static void main(String[ ] args) { } static void chicken(){ sayHello(); sayHello(); } }

14th Oct 2017, 8:42 PM
oyl
2 Respuestas
+ 8
The main method is the starting point of the program. So, start by reading all the code in the main method. There is no code in the main method. Therefore, the program is finished and exits successfully. Try calling the chicken method from the main method. Like so: chicken();
14th Oct 2017, 8:50 PM
Rrestoring faith
Rrestoring faith - avatar
+ 3
Exactly like Rrestoring faith said. Or if you want you can call sayHello(); too
14th Oct 2017, 9:03 PM
Daniel
Daniel - avatar