What is the result?

Given:
<code>
public class x{
public static void main (string [] args){
String theString = “Hello World”;
System.out.println(theString.charAt(11));
}
}
</code>
What is the result?

Given:

public class x{
public static void main (string [] args){
String theString = "Hello World";
System.out.println(theString.charAt(11));
}
}

What is the result?

A.
There is no output

B.
d is output

C.
A StringIndexOutOfBoundsException is thrown at runtime

D.
An ArrayIndexOutOfBoundsException is thrown at runtime

E.
A NullPointException is thrown at runtime

F.
A StringArrayIndexOutOfBoundsException is thrown at runtime

Explanation:

There are only 11 characters in the string “Hello World”. The code theString.charAt(11) retrieves the
12th character, which does not exist. A StringIndexOutOfBoundsException is thrown.
Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range:
11



Leave a Reply 0

Your email address will not be published. Required fields are marked *