Vidyalelo
Java Programming · Q6

Strings

Programming · Java Programming · question 6

Q6

Which of the following is true about Java strings?

A.
Strings are mutable.
B.
Strings can contain only letters.
C.
Strings can have a null value.
Answer
D.
Strings are implemented as arrays of characters.

Answer: Option C

Solution

Answer: Option C
Solution:
Java strings are sequences of characters used to store and manipulate text data.

Option A: Strings are mutable. → False. Java strings are immutable, meaning once a string is created, its value cannot be changed. If modifications are needed, a new string is created instead.

Option B: Strings can contain only letters. → False. Java strings can contain letters, numbers, symbols, spaces, or any other character. For example, "Hello123!" and "Java@2024" are valid strings.

Option C: Strings can have a null value. → True. A string variable can be assigned null, which means it does not reference any object in memory.

Option D: Strings are implemented as arrays of characters. → True, but incomplete. Java internally represents strings as character arrays (char[]), but they are encapsulated in the String class, and we generally use methods rather than directly accessing the array.

Thus, the correct answer is Option C: Strings can have a null value..