Examveda

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

This Question Belongs to Java Program >> Strings

Join The Discussion

Comments (1)

  1. Hritik Rohan
    Hritik Rohan:
    9 months ago

    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

Related Questions on Strings