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                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   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 class immutable
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How to make class immutable
Answer
# 1
1. Don't provide any methods that modify the object 
2. Ensure that no methods may be overridden. This prevents 
careless or malicious subclasses from compromising the 
immutable behavior of the class. Preventing
method overrides is generally done by making the class final
3. Make all fields final. 
4. Make all fields private. This prevents clients from 
modifying fields directly.
 
Is This Answer Correct ?    0 Yes 0 No
Kanchan
 
  Re: How to make class immutable
Answer
# 2
Make the class as final..
like
public final class String
 
Is This Answer Correct ?    6 Yes 1 No
A Kumar
 
 
 
  Re: How to make class immutable
Answer
# 3
Steps:
 1. Create class as final class
 2. Make all the properties i.e instance variable as final.
 3. Avoid or make the least access for the setter method 
for properties.
 
Is This Answer Correct ?    0 Yes 0 No
Vijayakumar Chinnasamy
 
  Re: How to make class immutable
Answer
# 4
declare calss as a final...
 
Is This Answer Correct ?    1 Yes 0 No
Ganesh Reddy
 
  Re: How to make class immutable
Answer
# 5
1. Declare the Class as final (this inherently makes all
member function final)
2. Declare member variables private (not necessarily final,
because private instance variable are accessed via public
member functions only, e.g. in java.lang.String class,
variable "hash" is declared as "private int hash;" with no
final keyword).
 
Is This Answer Correct ?    0 Yes 0 No
Al Rahid
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
What is adapter class?  2
Which Math method is used to calculate the absolute value of a number? Accenture3
Can we place the any object to key attribute of HashMap<key,value>? HCL3
What is the difference between error and exception and explain in simple words not whatever is given in the book.  6
What is a method ?  4
How applets will communicate with each other?  1
Can a class inherit the constructors of its superclass? Wipro7
what is bytecode ?explain in detail and watz the difference between bytecode and machine code? Lucent3
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
why ,we are using jsp and html.which one is better? Photon1
write java code to print second max number in the array Huawei9
What is meant by Encapsulation? Can you write a class to explain encapsulation? Ness-Technologies8
How many ways can an argument be passed to a subroutine?  2
What is the difference between Resultset and Rowset. IBM5
write a class to input 2 points by the user & check the line maked by the points is horizontal,vertical or rectangle?  1
strings in java are objects.why?  2
What is stop(), suspend(), resume() method?  3
what is the use of datasource in core java? Satyam2
what is generics in jdk1.5? Bally-Technologies1
What is meant by event handling?  1
 
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