Given:
Which statement is true?
Given:
Which statement is true?
The code fails to compile at line n1 because the 'var' keyword cannot be used to declare instance variables in Java. The 'var' keyword is only allowed for local variable declarations within methods, constructors, or initialization blocks. Therefore, using 'var' to declare the instance variable 'a' at line n1 will result in a compilation error.
Where can var be used? var can be used for declaring local variables, including index variables of for-loops and resource variables of the try-with-resources statement. var cannot be used for fields, method parameters, and method return types. From Java 11 you can use var in lambda expressions
C is correct
C var keyword cannot be used for declaring global variables or class-level variables.
C is correct
Tested: C.