Java Reseting alll values in the program

Posted on 2009-04-28
Last Modified: 2013-11-23
Hi, I am working on this program where at the end of the game I ask the user if they want to play again.  If they say yes, I need to start a new game.  I made a restart()

public void restart(){
            Game g = new Game();

However when I call this method some of the values in my program still at what they were during the previous game.

Is there a game to just clear everything and create an new instance of the game with all the default values?
Question by:ubuntuguy
    LVL 9

    Assisted Solution

    Where are you storing these values? You should put them as attributes for the Game class (but not static).
    LVL 3

    Assisted Solution

    It is hard to say but that variables that stay at their previous values are not just static to class?
    LVL 7

    Accepted Solution

    The reason we ask this, is because the static variables "follow" the class, and not the instantiated objects.

    A static class variable will not change as you create instances of the class.
    LVL 1

    Author Comment

    Hi sorry I was making a mistake.... I was calling the reset method not the restart one... lol.. sorry.... although I learned something about static variables  in this thread that i didnt know

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now