+ 2

What is wrong with this code?

boolean button =true; public void playMusic(){ if (button){ System.out.println("play music"); }else{ System.out.println("music paused"); } }

9th Oct 2017, 12:09 AM
Code Race
Code Race - avatar
4 Answers
+ 14
public class Program { public static void main(String[] args){ boolean button =true; playMusic(button); } static void playMusic(boolean button){ if (button){ System.out.println("play music"); }else{ System.out.println("music paused"); } } } //corrected program , it will work â˜ș //mark john wells sir answer as best , sir is right
9th Oct 2017, 2:48 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 5
If you are calling it from main and declaring it within the Program class, it needs to be static.
9th Oct 2017, 12:48 AM
John Wells
John Wells - avatar
+ 3
nothing. what error are you getting?
9th Oct 2017, 12:21 AM
LordHill
LordHill - avatar
+ 3
if you make it static, you will need to also make your variable static
9th Oct 2017, 12:50 AM
LordHill
LordHill - avatar