Which of the following is a mutable class in java?*1 pointjava.lang.Stringjava.lang.Bytejava.lang.Shortjava.lang.StringBuilder
Question
Which of the following is a mutable class in Java?
java.lang.String
java.lang.Byte
java.lang.Short
java.lang.StringBuilder
Solution
The mutable class in Java from the given options is java.lang.StringBuilder.
Here's why:
-
java.lang.String: Strings in Java are immutable, which means once a String object is created it cannot be changed. If any operation is performed on the String, a new String is created.
-
java.lang.Byte: Byte is a wrapper class in java. It is immutable because it does not provide any method to change its state after it is created.
-
java.lang.Short: Short is also a wrapper class in java. It is immutable for the same reason as Byte.
-
java.lang.StringBuilder: StringBuilder
Similar Questions
Which of the following is NOT a primitive data type in Java? A. short B. char C. String D. boolean
Which of these class is highest in hierarchy in javajava.lang.Exceptionjava.lang.Errorjava.lang.Throwablejava.lang.Object
Using sample code segments, explain the following concepts as used in Java: [6 marks]i. Object-ii. Classiii. Method
Which of the following keyword is used to create an object in java?Options: Pick one correct answer from belowcreatenewimplementsextends
Which of the following are Java primitive data types? You can select more than one answer.Group of answer choicesArrayintbooleanstringClass
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.