/*
How to make our classes as immutable clas by using Java programming?
*/
final class Employee
{
final int id;
final String name;
public Employee(int id,String name)
{
this.id=id;
this.name=name;
}
public int getId()
{
return id;
}
public String getName()
{
return name;
}
}
class ImmutableClass
{
public static void main(String[] alt)
{
Employee e1=new Employee(222,"Samar");
System.out.println(e1.getId()+" = "+e1.getName());
Employee e2=new Employee(333,"Athar");
System.out.println(e2.getId()+" = "+e2.getName());
}
}
How to make our classes as immutable clas by using Java programming?
*/
final class Employee
{
final int id;
final String name;
public Employee(int id,String name)
{
this.id=id;
this.name=name;
}
public int getId()
{
return id;
}
public String getName()
{
return name;
}
}
class ImmutableClass
{
public static void main(String[] alt)
{
Employee e1=new Employee(222,"Samar");
System.out.println(e1.getId()+" = "+e1.getName());
Employee e2=new Employee(333,"Athar");
System.out.println(e2.getId()+" = "+e2.getName());
}
}
0 Comment to "How to make our classes as immutable class by using Java programming?"
Post a Comment