---
title: "How to create Immutable class?"  
description: "How to create Immutable class?"  
author: "Anonymous User"  
published: 2015-04-27  
updated: 2020-09-21  
canonical: https://www.mindstick.com/interview/2439/how-to-create-immutable-class  
category: "java"  
tags: ["java", "string"]  
reading_time: 1 minute  

---

# 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;
}

}
```

\
\

## Answers

### Answer by Anonymous User

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;
}

}
```

\
\


---

Original Source: https://www.mindstick.com/interview/2439/how-to-create-immutable-class

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
