Examveda
Examveda

What is the maximum value that can be stored in a byte variable in Java?

A. 127

B. 255

C. 32767

D. 64

Answer: Option A

Solution(By Examveda Team)

In Java, the byte data type is a signed 8-bit integer type. Being signed means that it can represent both positive and negative values. The maximum value that can be stored in a byte variable is 127.

The reason is that a byte variable uses 8 bits to represent numbers, and one of those bits is used to represent the sign (positive or negative). Therefore, the remaining 7 bits are available to represent the magnitude of the number.

In binary, with 7 bits, you can represent numbers from 0 to 127. The highest bit (leftmost bit) is used for sign, where 0 represents positive and 1 represents negative.

So, the maximum value for a byte variable in Java is 2^7 - 1, which equals 127.

Therefore, the correct answer is Option A: 127.

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

Join The Discussion

Comments ( 1 )

  1. Test Mail
    Test Mail :
    7 months ago

    correct ans is A. Byte range is -128 to +127

Related Questions on Data Types and Variables