Page 1 of 1

About Question enthuware.ocpjp.v21.2.3699 :

Posted: Mon Mar 03, 2025 5:59 am
by n199a_
Given:

Code: Select all

record Student(int id, String name) { }  
Which of the following methods will be added automatically to this record?

Code: Select all

public String getName(){ return name; }

Code: Select all

public setName(String name){ this.name = name; }

Code: Select all

public final boolean equals(Object)

Code: Select all

public final int hashCode() 

Code: Select all

public final String toString()
None of the answers are correct because the compiled code looks like this:

Code: Select all

public record Person(int id, String name) {
    public Person(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public int id() {
        return this.id;
    }

    public String name() {
        return this.name;
    }
}

Re: About Question enthuware.ocpjp.v21.2.3699 :

Posted: Mon Mar 03, 2025 6:18 am
by admin
Did you read the explanation? and how do you know the compiled class looks like what you have posted?

btw, record name is Student and you have posted code for Person.