【发布时间】:2018-04-08 18:20:30
【问题描述】:
是否可以通过构造函数在方法中发送我需要的变量?
我有 2 个文件:
public class Recording {
public int height;
public int diameter;
public int weight;
public Recording (int height, int diameter, int weight) {
this.height = height;
this.diameter = diameter;
this.weight = weight;
}
}
和
public class Leergut {
public static void main(String[] args) {
int height;
int diameter;
int weight;
int code;
int pfand;
while (code != -1) {
Recording r = new Recording(System.in.read(), System.in.read(), System.in.read());
classify(r);
} else {
// to be continued
}
}
public static int classify(Recording r) {
if (height == 250 && diameter = 67 && weight == 365) { code = 0; return code;}
else { code = -1; return code ;}
}
我正在寻找一种将高度、直径和重量(如 Recording 类中声明的)传递给“分类”方法的方法。
或者我是否需要在方法中再次声明变量,以使其工作?
PS:对于那些试图在我的第一个帖子中帮助我的人,我决定发布一个新帖子,因为它可以提供更好的概述。
【问题讨论】:
-
投了反对票,因为这个问题表明对基本语言特征没有理解。您应该阅读一些面向初学者的 Java 教程或 Java 书籍。