HOW TO CREATE IMMUTABLE CLASS?

Mayank Tripathi

Total Post:807

Points:4035
Posted by  Mayank Tripathi
Java  String 
 608  View(s)
Ratings:
Rate this:
  1. Mayank Tripathi

    Post:807

    Points:4035
    How to create Immutable class?

    Create immutable class by creating final class that have final data members


    we have created a final class named Employee. It have one final datamember, a parameterized constructor and getter method
    public final class Employee{  
    final String pancardNumber;  
      
    public Employee(String pancardNumber){  
    this.pancardNumber=pancardNumber;  
    }  
      
    public String getPancardNumber(){  
    return pancardNumber;  
    }  
      
    } 


      Modified On Apr-27-2015 12:25:29 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!