Question: /\* I creates an `Employee` class, and one instance variable `A`, and I've overridden `toString()` method.

```
I created a test class in which I create a `List` of `Employee` type. After creating `Employee` object `obj`, I initialized `A` variable using `obj.A=10` and added this obj into the `List` with `add(obj)`. In the next line I initialized `obj.A=13` and added into the list with `add(obj)`. This way I added a  different value to the list. 

When I iterateover the List to display it, I see only the last value multiple times. Why is that? What should I do if I want to save different values using a single object and a single instance variable?*/

package com.swt;

/**
 *
 * @author RISHI
 */
public class Employee {
    public int a;
    Employee ()
    {}

    public int getA() {
        return a;
    }

    public void setA(int a)
 {

        this.a = a;
    }

    @Override

    public String toString() 
{

        return "Employee{" + "a=" + a + '}';
    }

}

package com.swt;

import java.util.ArrayList;
import java.util.List;
public class EmployeTest {

    public static void main(String[] args) 
{
            List<Employee> al=new ArrayList<Employee>();

            Employee obj=new Employee();

            obj.a=10;

            al.add(obj);

            obj.a=13;

            al.add(obj);

            obj.a=15;`enter code here`

            al.add(obj);

            for(Employee e:al)
{

                System.out.println("your list iteam value is"+e);
            }
    }

```

Answer: 
You are adding the same `Employee` object multiple times to the list. That's why all the `Employee`s in the list have the same data (since they are the same object).

You have to create a new instance before each time you want to add an Employee to the list.

```
List<Employee> emps = new ArrayList<Employee>();
Employee emp = new Employee (); // create first employee
emp.A = 10;
emps.add(emp); // add first employee
emp = new Employee(); // create second employee
emp.A = 13;
emps.add(emp); // add second employee

```
You created only one instance. You made changes on it and inserted into the list again and again. As they are all same object they all get the latest value.