Java OCA OCP Practice Question 1568

Question

What will the following code print?

System.out.println ("12345".charAt (6));

Select 1 option

A. 5
B. null
C. -1
D. It will throw an ArrayIndexOutOfBoundsException.
E. It will throw a StringOutOfBoundsException.
F. It will throw an  IndexOutOfBoundsException


Correct Option is  : F

Note

Since indexing starts with 0, the maximum value that you can pass to charAt is length-1.




PreviousNext

Related