Kate's friend

Report a typo

Given the following class Person that allows creation of people along with the reference for their best friend. What would be printed out?

public class Person {
    private final String name;
    private final Person bestFriend;

    public Person(String name) {
        this.name = name;
        this.bestFriend = new Person(name + "'s friend");
    }

    public String getName() {
        return name;
    }

    public Person getBestFriend() {
        return bestFriend;
    }

    public static void main(String[] args) {
        Person person = new Person("Kate"); // line 1
        System.out.println(person.getBestFriend().getName()); // line 2
    }
}
Select one option from the list
___

Create a free account to access the full topic