GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Microsoft  >  Microsoft.NET
Go To First  |  Previous Question  |  Next Question 
 Microsoft.NET  |  Question 31 of 38    Print  
What is meant by Mutable and Immutable classes?

  
Total Answers and Comments: 6 Last Update: February 23, 2009     Asked by: Khader Hassan Khan M 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
March 26, 2007 09:06:33   #1  
kvmahesh_ukt        

RE: What is meant by Mutable and Immutable classes?
Immutable type are types whose instance data fields and properties does not change after the instance is created. Most value types are immutable but the mutable type are A type whose instance data fields and properties can be changed after the instance is created. Most Reference Types are mutable.

Shortly we can say as:

When you have a reference to an instance of an object the contents of that instance can be altered for Mutable objects and When you have a reference to an instance of an object the contents of that instance cannot be altered for Immutable objects.

 
Is this answer useful? Yes | No
April 04, 2007 17:12:01   #2  
Sanjiv Sharma        

RE: What is meant by Mutable and Immutable classes?

To put light on this:-
When u change the value of Mutable objects the new memory is created and new
value is stored in new memory.
But in immutable the value is changed in same memory this makes immutable objects to increase the performance.

so in case if the string is frequently changed in the code at run time it is advisable to use immutable objectes.


 
Is this answer useful? Yes | No
August 03, 2007 20:58:42   #3  
Tejas        

RE: What is meant by Mutable and Immutable classes?

Hi Sanjiv I am a bit confused here.

String is a immutable class. It is advised if the value of the string
varaible is going to change from time to time then we use a StringBuilder which is a mutable class.

Hence when u change the value of as instance of string object (instance of immutable class) then new memory is created and value is stored in the new memory where as if you assign a new value to an instance of StringBuilder class then value is changed in the same memory and this gives a performance improvement.

So in case if the string is frequently changed in the code at run time it is advisable to use mutable objectes.


 
Is this answer useful? Yes | No
February 18, 2008 20:34:40   #4  
amitkumar316 Member Since: February 2008   Contribution: 9    

RE: What is meant by Mutable and Immutable classes?
immutable classes are read-only classes. once declared their value cannot be changed & its vice-versa are mutable classes.
 
Is this answer useful? Yes | No
July 30, 2008 11:16:30   #5  
bobby420 Member Since: July 2008   Contribution: 1    

RE: What is meant by Mutable and Immutable classes?
Best Example to understand Mutable and Immutable is string.
string class is immutable.
so if
string x 123 ;
if you do x x + abc what it does is it assigns new memory location for 123 and abc.
Then adds the two strings and places the computed results in new memory location and points x to it.

if you use
System.Text.StringBuilder sb new System.Text.StringBuilder( 123 );
sb.Append( abc );
x sb.ToString();

stringbuilder is mutable class. It just adds the string to same memory location.
This way string manipulation is faster.

I hope this helps.

 
Is this answer useful? Yes | No
February 23, 2009 05:51:12   #6  
rajkra Member Since: February 2009   Contribution: 2    

RE: What is meant by Mutable and Immutable classes?
Instances cannot be changed but it can be accessed are called Immutable.
Instances can be changed are called mutable.

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape