• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

immutable

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The StringBuffer class is NOT immutable. And that is a fact.
[ January 10, 2004: Message edited by: Vicken Karaoghlanian ]
reply
    Bookmark Topic Watch Topic
  • New Topic