Zuordnung für Array und dann mit Konstruktor

Person.java
<code>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);
    }
}
</code>
PersonTest.java
<code>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());
        }
    }
}
</code>

Im obigen Code haben wir zweimal "neu" verwendet. Ist dieser Code richtig oder falsch? Die erste dient zur Zuweisung des Arrays. Aber warum der zweite? Es ist aus Vorlesungsskripten.

Antworten auf die Frage(3)

Ihre Antwort auf die Frage