0
所以我想通過從另一個類啓動一個方法 來使用主類中的對象。到目前爲止,我有這個。任何人都可以告訴我我做錯了什麼,或者如果有可能以另一種方式?從另一個類處理對象初始化
main.java
public class main extends index {
public static void main(String []args) {
index();
System.out.print(object1.getVal1);
}
}
index.java
public class index {
public static void index() {
list object1 = new list(val1, val2);
}
list.java
public class list {
//constructors
private static int val1;
private static int val2;
public list(val1, val2) {
this.setVal1(val1);
this.setVal2(val2);
//setters and getters look like this for both val1 and val2
public static int getVal1() {
return val1;
}
public void setVal1(int val1) {
this.val1 = val;
}
}