Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


samar
immutable class
1 Answer(s)      3 years and 11 months ago
Posted in : Java Interview Questions


How to make a class immutable?

Advertisement
View Answers

October 29, 2010 at 6:19 PM


Hi,

To make a class immutable,

  1. Don't provide any methods that modify the object.

  2. Ensure that no methods may be overridden.

  3. Mark the class as final.

  4. Make all fields final and private.

Thanks.



Related Tutorials/Questions & Answers:
immutable class
immutable class  How to make a class immutable
Immutable Image using Canvas Class
Immutable Image using Canvas Class   ... to create the immutable image using canvas. In this example ImageCanvas class extends the Canvas class to create the immutable image. In the constructor
Advertisements
IMMUTABLE - Java Interview Questions
IMMUTABLE  How To Make A Class Immutable?  Hi Friend, To make a class immutable we must restrict changing the state of the class...; } } public class Immutable{ public static void main(String[] args
String immutable - Java Beginners
String immutable  Why is String immutable?  See here Why String is immutable in Java
Mutable and immutable Objects - Java Beginners
Mutable and immutable Objects  Hi, Please tell me about Mutable and immutable Objects. What is mutable object and immutable object and how... we can alter. like any primitive. Immutable are those object whcih we can
what is mutable and immutable object in java ?difference ?
what is mutable and immutable object in java ?difference ?  what is mutable and immutable object in java ?difference
STRING IMMUTABLE - Java Interview Questions
STRING IMMUTABLE  Why string objects are immutable? what is the region behind?i want regione plz replyyyyyyyyy  Hi Friend, JVM maintains... object is immutable. Thanks
Immutable Image MIDlet Example
Immutable Image MIDlet Example       This is the immutable image example, which shows how to create a immutable image in MIDlet. In this example we are creating
class
class  Is a class a subclass of itself
class
is a class to represent a country in medal tally. It has an attribute of country... medals. In this class, you should also define constructors, and assessor, mutator methods. Task 2 MedalTally.java is a class to model a medal tally, containing
Class
Class, Object and Methods       Class : Whatever we can see in this world all the things... is termed as a class. All the objects are direct interacted with its class
Wrapper Class
are immutable i.e. once assigned a value to a wrapper class instance cannot be changed...Wrapper Class  what is wrapper class in java and why we use it   Hi Friend, Wrapper class is a wrapper around a primitive data type
(ii) String and String Buffer Class
String and String Buffer Class  difference between String and String Buffer Class... between String and StringBuffer 1) String object is immutable
Super class of an Exception class
Super class of an Exception class  hello,,, What is super class of an Exception class?   hii,, the super class of an exception is throwable class. and the super class of an throwable class is the object class
Class
Class       This section explores the concept of a class in reference to object oriented programming techniques. A class defines the properties of  objects and methods used
Explain final class, abstract class and super class.
Explain final class, abstract class and super class.  Explain final class, abstract class and super class.   Explain final class, abstract class and super class. A final class cannot be extended. A final class
.class and .tld
.class and .tld  how to create .class and .tld file
class file
class file  How to create class file in jsf easily
class loaders
class loaders   Explain static and dynamic class loaders
inner class
inner class  what is mean by inner class   Inner class is a non-static class which is defined inside another class
Node class
Node class   hii, What is a node class?   hello, A node class is a class that has added new services or functionality beyond the services inherited from its base class
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
wrapper class
wrapper class  list wrapper class methods
printstrim class
printstrim class  discribe PrintStream class
Abstract class
Abstract class  what is an Abstract class
Abstract class
Abstract class  Can an abstract class be final
Locale class
Locale class  What is the Locale class
Java class
Java class  What is the purpose of the Runtime class
wrapper class
wrapper class  wrapper class methods
printstrim class
printstrim class  discribe PrintStream class
Advertisements
 

 

 

DMCA.com