nerdexam
Oracle

1Z0-803 · Question #6

Given: What is the result?

The correct answer is C. A StringIndexOutOfBoundsException is thrown at runtime. 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

Working with Selected Classes from the Java API

Question

Given:

What is the result?

Exhibit

1Z0-803 question #6 exhibit

Options

  • AThere is no output
  • Bd is output
  • CA StringIndexOutOfBoundsException is thrown at runtime
  • DAn ArrayIndexOutOfBoundsException is thrown at runtime
  • EA NullPointException is thrown at runtime
  • FA StringArrayIndexOutOfBoundsException is thrown at runtime

How the community answered

(38 responses)
  • A
    3% (1)
  • C
    87% (33)
  • D
    8% (3)
  • E
    3% (1)

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

Topics

#string methods#string indexing#StringIndexOutOfBoundsException#runtime exceptions

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice