Which keyword is used to declare a variable that can hold a reference to an object of any class in Java?
A. object
B. class
C. var
D. generic
Answer: Option C
Solution(By Examveda Team)
The correct answer is Option C: var.In Java, the var keyword is used to declare a variable that can hold a reference to an object of any class without specifying the exact data type explicitly. It was introduced in Java 10 to support local type inference.
Here's the breakdown:
Option A: object - There is no object keyword for declaring variables with generic reference types in Java.
Option B: class - The class keyword is used for defining and declaring classes in Java, not for declaring variables with generic reference types.
Option C: var - This is the correct answer. The var keyword is used for declaring variables with inferred types, allowing them to hold references to objects of any class.
Option D: generic - The term generic usually refers to generic types and classes in Java, but it is not a keyword used for declaring variables.
So, the keyword used to declare a variable that can hold a reference to an object of any class in Java is var.
Related Questions on Data Types and Variables
What is the maximum value that can be stored in a byte variable in Java?
A. 127
B. 255
C. 32767
D. 64
What is the default value of an int variable in Java if it's not explicitly initialized?
A. 0
B. 1
C. -1
D. Null
Which of the following is not a valid identifier for a Java variable?
A. my_var
B. _myVar
C. 3rdVar
D. $var
Join The Discussion