gpt4 book ai didi

Java,在类中使用变量

转载 作者:行者123 更新时间:2023-12-01 16:00:17 24 4
gpt4 key购买 nike

如何在不同的类中使用变量drawMax?

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

最佳答案

假设您的drawNumberSetting(int drawMax)是在类A中声明的。这意味着具有类A实例的任何其他类都可以调用该方法并使用返回值。

class B
{
public void my otherMethod()
{
A a = new A();
int drawMax = a.drawNumberSetting(5);
}
}

关于Java,在类中使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4143339/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com