Exam 1z0-829 All QuestionsBrowse all questions from this exam
Question 6

Given the code fragment:

Which action enables the code to compile?

    Correct Answer: E

    The keyword 'record' in Java allows only instance methods and variables to be defined. However, the error here is because a record cannot have non-static instance fields outside of constructor parameters. Therefore, making 'regNo' a static variable will allow the code to compile since static fields are allowed in records. The correct action is to make the 'regNo' variable static.

Discussion
james2033Option: E

package q06; record Product(int pNumber, String pName) { // int regNo = 100; static int regNo = 100; public int getRegNumber() { return regNo; } } public class App { public static void main(String[] args) { Product p1 = new Product(1111, "Ink Bottle"); } }

minhdevOption: E

E is correct answer. record allows static variable.

UtemanOption: E

E is correct Records only allow static variables

xplorerpjOption: E

E is correct answer