1z0-819 Exam QuestionsBrowse all questions from this exam

1z0-819 Exam - Question 94


Which two var declarations are correct? (Choose two.)

Show Answer
Correct Answer: ACD

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.

Discussion

3 comments
Sign in to comment
StavokOptions: AC
Jun 7, 2023

A and C are correct

[Removed]
Aug 30, 2023

var identifier is allowed, '_' is not allowed. Only var y = (String) null; for example is allowed SO A & C are correct.

ASPushkinOptions: AD
Jun 23, 2024

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