What will be the output of the following code? public class Demo { public…
2024
What will be the output of the following code? public class Demo { public static void main(String[] args) { String str = "Hello"; str = str + "World"; str = str.substring(5,10); System.out.println(str); } }
Answer: D. World — The string becomes HelloWorld. substring(5, 10) returns the characters from index 5 up to index 9, which is World.
- A.
Hello
- B.
Hello World
- C.
ello
- D.
World
- E.
Question not attempted
Attempted by 213 students.
Show answer & explanation
Correct answer: D
The string becomes HelloWorld. substring(5, 10) returns the characters from index 5 up to index 9, which is World.
Loading lesson…