Which two var declarations are correct? (Choose two.)
Which two var declarations are correct? (Choose two.)
The correct declarations are 'var names = new ArrayList<>();' and 'var y = null;'. The first declaration is correct as 'var' can infer the type of 'ArrayList'. The second declaration is correct because 'var' can infer the type of a variable initialized to 'null' based on further assignments. The declaration 'var var = “hello”;' is incorrect because 'var' cannot be used as a variable name. Similarly, 'var _ = 100;' is incorrect because '_' is a reserved keyword and cannot be used as an identifier. The declaration 'var a;' is incorrect because 'var' requires an initializer to infer the type.
A. it works var will infer the type of list to be ArrayList<Object> --- DE var can only be used when there is an initializer. var person = null; // ERROR --- C Ok var isn't keyword ----- B. failed as of release 9, '_' is a keyword, and may not be used as an identifier
var identifier is allowed, '_' is not allowed. Only var y = (String) null; for example is allowed SO A & C are correct.
A and C are correct