How many of the following lines of code compile?
char one = Integer.parseInt("1"); Character two = Integer.parseInt("2"); int three = Integer.parseInt("3"); Integer four = Integer.parseInt("4"); short five = Integer.parseInt("5"); Short six = Integer.parseInt("6");
C.
The parseInt()
method returns an int primitive.
Via autoboxing, we can assign int to an Integer wrapper class object reference.
The char and short types are smaller than int so they cannot store the result.
Lines 3 and 4 compile, and Option C is correct.