Java OCA OCP Practice Question 1375

Question

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"); 
  • A. None
  • B. One
  • C. Two
  • D. Three
  • E. Four
  • F. Five


C.

Note

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.




PreviousNext

Related