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.
D. Strings are implemented as arrays of characters.
Answer: Option C
Solution (By Examveda Team)
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..
Join The Discussion
Comments (1)
Related Questions on Strings
In Java, which class is used to represent a sequence of characters as a string?
A. String
B. StringBuilder
C. StringSequence
D. StringArray
What is the correct way to create a new empty String object in Java?
A. String emptyString = "";
B. String emptyString = new String();
C. String emptyString = " ";
D. String emptyString = null;
E. Both A and B
Which of the following methods is used to compare two strings for equality in Java?
A. equals()
B. compareTo()
C. equalsIgnoreCase()
D. compare()
A. Strings are mutable.
False for most programming languages like Java and Python. Strings are immutable, meaning their values cannot be changed once created. Operations on strings typically result in a new string.
B. Strings can contain only letters.
False. Strings can contain letters, digits, special characters, or even whitespace. There is no restriction to letters only.
C. Strings can have a null value.
True in many programming languages (like Java, C++, etc.), strings can have a null value, representing no reference or an uninitialized state.
D. Strings are implemented as arrays of characters.
True. In many programming languages, strings are internally implemented as arrays (or sequences) of characters, though the exact implementation may vary by language.
A: False
B: False
C: True
D: True