Question discussion

Which of the following is the correct way to declare a variable in Java?

358852Medium DSSSB TGT Computer Science 0 replies 0 views
0
Which of the following is the correct way to declare a variable in Java?
  • Alet x = 10;
  • Bx = 10;
  • Cvar x = 10;
  • Dint x = 10;
Correct answer: D

Explanation

In Java, a variable is declared with its data type, as in int x = 10;. 'let' is JavaScript and 'var' (type inference) works only in newer versions inside methods.

Discussion 0

Nobody has replied yet. Start the discussion!