Java Programming: I keep getting the following non-static variable error: Game.j
ID: 3727771 • Letter: J
Question
Java Programming: I keep getting the following non-static variable error: Game.java:30: error: non-static variable RestartGame cannot be referenced from a static contextif (RestartGame == true) ^1 error
Here is the code I am trying to run. There are more methods but I have pasted the code you will probably need to answer the question
Many Thanks
import java.util.Scanner;
public class Game {
private Boolean RestartGame == true;
public static void main (String args[])
{
Game Program = new Game();
{
Program.NumberOfRoundsToPlay(); // Gets User Input of How Many Round of Game They would like to Play
Program.StartRounds(); // The Actual Game
Program.RestartGame(); // Checks User Input to See if User would like to Replay the game
}
}
Explanation / Answer
//Note:- if you have any query then comment below.please upvote.
//if you found error then upload all the part of the code.
import java.util.Scanner;
public class Game {
private static Boolean RestartGame = true;
public static void main (String args[])
{
Game Program = new Game();
while (RestartGame == true)
{
Program.NumberOfRoundsToPlay(); // Gets User Input of How Many Round of Game They would like to Play
Program.StartRounds(); // The Actual Game
Program.RestartGame(); // Checks User Input to See if User would like to Replay the game
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.