allocating for array and then using constructor

后端 未结 3 867
终归单人心
终归单人心 2021-01-21 05:23

Person.java

public class Person {
    public String firstName, lastName;

    public Person(String firstName,
            String lastName) {
        this.firstN         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-21 06:05

    Yes, it is correct.

    The line:

    Person[] people = new Person[20]
    

    allocates the array, full of references to null while the line:

    new Person(NameUtils.randomFirstName(),
                          NameUtils.randomLastName());  //this line
    

    fills it [the array] by instantiating objects of type Person, and assigning the reference in the array.

提交回复
热议问题