Given:
and the code fragment:
Which two lines cause compilation errors? (Choose two.)
Given:
and the code fragment:
Which two lines cause compilation errors? (Choose two.)
Lines 6 and 7 cause compilation errors. The 'var' keyword in Java is used to infer the type of a local variable at compile time. However, 'var' cannot be used for member variables (fields) in a class, method parameters, or return types. In the code fragment provided, 'var' is incorrectly used for the field 'employee' in line 6 and as a method return type in line 7, both of which are not allowed.
AE 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
yes +1
var cannot be used for fields instance, method parameters, and method return types.