Given the code fragment:
Which action enables the code to compile?
Given the code fragment:
Which action enables the code to compile?
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.
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"); } }
E is correct answer. record allows static variable.
E is correct Records only allow static variables
E is correct answer