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");
- A.
Only I
- B.
Only II
- C.
Both I and II
- 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.