【发布时间】:2020-04-15 02:24:11
【问题描述】:
我想将数组作为对象的参数传递,但我是一种堆栈。 所以这是我的问题。
public class Publisher {
public static void main(String args[]) {
String teachers[] = {"Jyothi", "Jyostna", "Sumathi"};
Publisher2 p1 = new Publisher2(teachers[1],20); //The problem is here, I can't specify
//index of array (I can put onlu teachers without index[1])so toString method is returning address of object instead of the name
System.out.println(p1);
}
}
class Publisher2 {
String[] teachers;
int y;
public Publisher2(String[] teachers, int y) {
this.teachers = teachers;
this.y = y;
}
@Override
public String toString() {
return "Publisher2{" + "teachers=" + teachers + ", y=" + y + '}';
}
}
【问题讨论】:
标签: java arrays object parameters