类访问跨多个JAVA类的变量
我是JAVA新手,正在编写一个在两个不同类之间传递变量的程序。我似乎不知道如何将变量的数据从一个类发送到另一个类,然后再发送回来?这可能吗
例如:
Public Class A {
Scanner input = new Scanner(System.in);
System.out.println("Please input the weight:");
bagWeight=input.nextDouble();
System.out.println("The total weight is: "+total);
}
Public Class B {
double number = 3;
public method(double number, double bagWeight)
{
total = bagWeight*number;
return total;
}
}
# 1 楼答案
当然这是可能的:有很多方法可以做到这一点
例如,您可以轻松做到这一点: