Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

immutable

 
dhana rangu
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following java classes are immutable??

A.java.lang.Math
B.java.util.String
C.java.util.StringBuffer
D.java.lang.Boolean
E.java.lang.Object

The answer is given as B,C.
But i doubt if StringBuffer class is immutable ..plz advise
dhana
 
Rama Kumar PV
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An object can be categorized as mutable if it can be changed internally (through the usage of methods).
Here, Math class cannot be instantiated and hence all it's methods are static. All wrapper classes are immutable along with String. StringBuffer represents mutable strings. So, possible answers can be, java.lang.Boolean and java.util.String and not StringBuffer.
Cheers,
Rama
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The StringBuffer class is NOT immutable. And that is a fact.
[ January 10, 2004: Message edited by: Vicken Karaoghlanian ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic