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. WorldThe string becomes HelloWorld. substring(5, 10) returns the characters from index 5 up to index 9, which is World.

  1. A.

    Hello

  2. B.

    Hello World

  3. C.

    ello

  4. D.

    World

  5. 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.

Explore the full course: Rssb Basic Computer Instructor

Loading lesson…