What is the range of values that can be stored in a short variable in Java?
A. -128 to 127
B. -32,768 to 32,767
C. 0 to 65,535
D. -1,000,000 to 1,000,000
Answer: Option B
Solution(By Examveda Team)
The correct answer is Option B: -32,768 to 32,767.In Java, a short variable is a 16-bit signed integer type, which means it can store values in the range of -32,768 to 32,767.
Here's the breakdown:
Option A: -128 to 127 - This range corresponds to a byte data type, not a short.
Option B: -32,768 to 32,767 - This is the correct range for a short variable in Java.
Option C: 0 to 65,535 - This range corresponds to an unsigned short (also known as char) in Java. A regular short is signed and can have both positive and negative values.
Option D: -1,000,000 to 1,000,000 - This range exceeds the capacity of a short variable, which can only store values up to 32,767.
So, the range of values that can be stored in a short variable in Java is -32,768 to 32,767.
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