Examveda

What is the range of values that can be stored in a char variable in Java?

A. 0 to 127

B. -128 to 127

C. 0 to 65535

D. -32768 to 32767

Answer: Option C

Solution (By Examveda Team)

The correct answer is Option C: 0 to 65535.

In Java, a char variable is used to represent Unicode characters, and it can store values within the range of 0 to 65535 (2^16 - 1). This range covers the entire Unicode character set, which includes characters from various scripts and symbols.

Here's the breakdown:

Option A: 0 to 127 - This range is not correct for a char variable. It represents a smaller range suitable for an 8-bit data type, such as byte.

Option B: -128 to 127 - This range is also not correct for a char variable. It represents a signed range, and char is an unsigned data type.

Option C: 0 to 65535 - This is the correct range for a char variable in Java, covering the entire Unicode character set.

Option D: -32768 to 32767 - This range is not applicable to a char variable. It represents a signed range suitable for a 16-bit signed data type, such as short.

So, the correct range of values that can be stored in a char variable in Java is 0 to 65535.

This Question Belongs to Java Program >> Data Types And Variables

Join The Discussion

Related Questions on Data Types and Variables