nerdexam
Oracle

1Z0-803 · Question #143

Given: public class Case { public static void main(String[] args) { String product = "Pen"; product.toLowerCase(); product.concat(" BOX".toLowerCase()); System.out.print(product.substring(4,6)); } } W

The correct answer is E. An exception is thrown at runtime. Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 6 at java.lang.String.substring(Unknown Source)

Working with Selected Classes from the Java API

Question

Given:

public class Case { public static void main(String[] args) { String product = "Pen"; product.toLowerCase(); product.concat(" BOX".toLowerCase()); System.out.print(product.substring(4,6)); } } What is the result?

Options

  • Abox
  • Bnbo
  • Cbo
  • Dnb
  • EAn exception is thrown at runtime

How the community answered

(30 responses)
  • A
    7% (2)
  • B
    3% (1)
  • C
    3% (1)
  • D
    13% (4)
  • E
    73% (22)

Explanation

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 6 at java.lang.String.substring(Unknown Source)

Topics

#String immutability#String methods#StringIndexOutOfBoundsException

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice