我开始学习java,当我可以到达对象名称和姓氏时遇到了这个问题,但是如果我把它们放在对象数组中就无法到达。
public class Human {
String name;
String lastName;
String[] people;
People(String name, String lastName) {
this.name = name;
this.lastName = lastName;
};
public static People tom = new People("Tom", "Tommy");
public static People ted = new People("Ted", "Teddy");
public static Object[] objects = {
tom,
ted
};
public static void main(String[] args) {
System.out.println(tom.lastName);
System.out.println(objects[0]);
我需要的这条线不起作用。
System.out.println(objects[0].lastName);
}