Which of the following methods will create string in Java? I: String S =…

2022

Which of the following methods will create string in Java? I: String S = "Hello Java"; II: String S2 = New string ("Hello Java");

  1. A.

    Only I

  2. B.

    Only II

  3. C.

    Both I and II

  4. D.

    Neither I nor II

Attempted by 206 students.

Show answer & explanation

Correct answer: A

In Java, Option I is correct because string literals are a valid way to create String objects. Option II is incorrect due to syntax errors: Java keywords are case-sensitive, so it must be 'new String', not 'New string'. Therefore, only Option I creates a valid string.

Explore the full course: Up Lt Grade Assistant Teacher 2025