Reputation: 2337
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;
}
Upvotes: 0
Views: 108
Reputation: 17775
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;
}
Upvotes: 0
Reputation: 44063
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);
}
}
Upvotes: 1