ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
How to make a class immutable?
 Question Submitted By :: Sudha
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How to make a class immutable?
Answer
# 1
Just Make the class as a final
 
Is This Answer Correct ?    8 Yes 7 No
Raju
 
  Re: How to make a class immutable?
Answer
# 2
dont provider setters and provide the parameter constructor
 
Is This Answer Correct ?    3 Yes 5 No
Teja
 
 
 
  Re: How to make a class immutable?
Answer
# 3
create a class , having some private variables and setter 
method for that variable , In constructor pass the 
arguments to set this variable.
 
Is This Answer Correct ?    0 Yes 4 No
Rahul
 
  Re: How to make a class immutable?
Answer
# 4
To make a class immutable, 
1. Don't provide any methods that modify the object.
2. Ensure that no methods may be overridden. Mark the class 
as final. Make all fields final and private.
 
Is This Answer Correct ?    12 Yes 0 No
Kanchan
 
  Re: How to make a class immutable?
Answer
# 5
1. Mark the class as 'final' to avoid any 
subclassing/overriding
2. Make the fields as 'private' & 'final' to avoid 
reassining in any way after creation of the object by 
passing params via contructor
 
Is This Answer Correct ?    2 Yes 0 No
Cm
 
  Re: How to make a class immutable?
Answer
# 6
1.Mark the class as final to avoid subclass, So subclass 
can't change any thing in super class.
2. When ever you are chaning any property of that class 
make a new instance of that calss.
e.g public modify(Object obj0)
{ 
ClassName a =new ClassName ();
a.modify()// modification logioc
}
 
Is This Answer Correct ?    0 Yes 0 No
Sudhakar Sahoo
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
what is an virtual function TCS2
What are Font and FontMetrics classes?  1
How can we handle runtime exceptions? write one sample program? Can we write runtime exceptions beside the throws key word? if yes write sample program? Huawei1
whats the life cycle of jsp Satyam11
Accenture NJ mostly ask question on Collection like 1)How to sort Objcts and how treeset sort them 2)Explain mechanism of Hashcode finding in Java 3)Name some of the Sorted collection. Accenture2
Hi Friends, can u give code to convert ArrayList to HashMap and HashMap to ArrayList.  1
what is auto boxing UHG1
when a servlet sends request for first time it uses the follwing methods a)init b)doget() c)dopost() d)service Accenture2
What is Interface? BMC5
How to create an instance of a class if the class has private constructor?  2
can we create object for static class in java Marlabs5
In Inheritence concept, i have a static method in super class and i am inheriting that class to one sub class.in that case the static method is inherited to sub class or not???? Accenture8
why the constructor should be used in class,if there is no constructor what will happen?  4
How to validate the request (Eg:user name and password) in session(http session)? not in LDAP server ? Saksoft1
Write a program to create a binary Tree ?  1
what is difference between excute query ()and execute update ()? Symphony5
what is the use of abstract class and interface with example? DNS2
What happens if an exception is not caught?  4
Explain pass by reference and pass by value? Wipro5
String is a immutable objects . it means that string does not change........... But it will be chang......... { String s="kapil"; String s1="raj"; String s=s1; then print(.......) The String has been changed .. how it is possible and why its called immutable objects  3
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com