0

How can I use the variable drawMax in a different class?

public int DrawNumberSetting (int drawMax)
{
    System.out.print ("Please enter the maximum number of draws you want to play: ");
    drawMax = scan.nextInt ();
    return drawMax;
}
5
  • you mean to say that you want to use a local method variable in another class? Please elaborate. Commented Nov 10, 2010 at 10:16
  • 4
    What do you want to do exactly? Commented Nov 10, 2010 at 10:16
  • I just want to use the value the user entered in this method, in another class I have. Is that possible? Commented Nov 10, 2010 at 10:21
  • why don't you try it out by your self. Commented Nov 10, 2010 at 10:21
  • Just provide drawMax to the other method. Really, can't get the point of your question. Commented Nov 10, 2010 at 10:28

2 Answers 2

1

Lets say your drawNumberSetting(int drawMax) is declared in class A. That means that any other class that has an instance of class A can call that method and use the returned value.

class B
{
    public void my otherMethod()
    {
        A a = new A();
        int drawMax = a.drawNumberSetting(5);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can turn drawMax into a class level variable and provide a getter\accessor method, like this:

private int drawMax;

public void DrawNumberSetting ()
{
    System.out.print ("Please enter the maximum number of draws you want to play: ");
    drawMax = scan.nextInt ();
}

public int getDrawMax()
{
   return drawMax;
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.