Immutable
package com.vishwa.immutable;
public final class Salary { final private int salaryAmount; final private Integer[] salaryComponent; public Salary(int salaryAmount, Integer[] salaryComponent) { super(); this.salaryAmount = salaryAmount; this.salaryComponent = salaryComponent; System.out.println(salaryComponent.toString()); } public int getSalaryAmount(){ return salaryAmount; } public Integer[] getSalaryComponent(){ return salaryComponent.clone(); } } |
package com.vishwa.immutable;
public class Test { public static void main(String[] args) { Integer[] salaryComponent = new Integer[10]; salaryComponent [0]= new Integer(10); salaryComponent [1]= new Integer(100); salaryComponent [2]= new Integer(1000); int salary =1110; Salary salaryObject = new Salary(salary,salaryComponent); System.out.println("salary"+salaryObject.getSalaryAmount()); System.out.println("salaryComponent"+salaryObject.getSalaryComponent().toString());; } } |