Person.java
public class Person {
public String firstName, lastName;
public Person(String firstName,
String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public String getFullName() {
return(firstName + " " + lastName);
}
}
PersonTest.java
public class PersonTest {
public static void main(String[] args) {
Person[] people = new Person[20]; //this line .
for(int i=0; i<people.length; i++) {
people[i] =
new Person(NameUtils.randomFirstName(),
NameUtils.randomLastName()); //this line
}
for(Person person: people) {
System.out.println("Person's full name: " +
person.getFullName());
}
}
}
上記のコードでは、「new」を 2 回使用しています。このコードは正しいですか、それとも間違っていますか? 最初のものは配列の割り当て用です。しかし、なぜ2番目の?講義ノートからです。