GIAC
GSSP-JAVA · Question #54
What will be the output of the following code snippet? class test22 { public static void main(String args[]) { String str= new String("Hello"); str.insert(3,"bye"); System.out.println(str); } }
The correct answer is D. It will generate a compile-time error. See the full explanation below for the reasoning.
Question
What will be the output of the following code snippet? class test22 { public static void main(String args[]) { String str= new String("Hello"); str.insert(3,"bye"); System.out.println(str); } }
Options
- AIt will display Hello.
- BIt will display Helbyelo.
- CIt will throw NFE.
- DIt will generate a compile-time error.
How the community answered
(39 responses)- A3% (1)
- B15% (6)
- C8% (3)
- D74% (29)
Community Discussion
No community discussion yet for this question.