Correct Answer : A
The most commonly used integer type is int
. It is a signed 32-bit (4 bytes) type that has a range from -2,147,483,648
to 2,147,483,647
. In addition to other uses, variables of type int
are commonly employed to control loops and to index arrays. Any time you have an integer expression involving byte
s, short
s, int
s, and literal numbers, the entire expression is promoted to int
before the calculation is done.
The int
type is the most versatile and efficient type and it should be used most of the time when you want to create a number for counting or indexing arrays or doing integer math. It may seem that using short
or byte
will save space, but there is no guarantee that Java won't promote those types to int
internally anyway. Remember, type determines behavior, not size. (The only exception is arrays, where byte
is guaranteed to use only one byte per array element, short
will use two bytes, and int
will use four.)