Given record P(int x, int y) {} and a variable p of type P, which expression reads the component x from another class?
Correct answer C. p.x()
Explanation
For each component, a record automatically has a public accessor method with the same name as the component, so p.x() is correct. Records do not follow the JavaBean getX naming pattern. The field x is private and final, so p.x fails outside the record's own body, and there is no general get method.
Answer checked How we write and check questions
Discussion