ExamVeda
Login
Home
Data Types and Variables
?

Which keyword is used to declare a variable that can hold a reference to an object of any class in Java?

Answer & Solution
Correct Answer: Option C
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.
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.