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)- A7% (2)
- B3% (1)
- C3% (1)
- D13% (4)
- E73% (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.