I am adding five objects in the list with the help of for loop. I am initializing my object outside the for loop. In the body of for loop i am changing the object setter properties and adding it in the list. The output with this is: It will add five objects but all have the same attributes even after setting the different values for the attribute.

See the following code

```
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ASD {
    public static void main(String args[]) {
        List list = new ArrayList<A>();
        System.out.println("Before Insert List is " + list);
        A obj = new A();

        for (int i = 0; i < 5; i++) {
            obj.setA(new Random().nextInt(10));
            list.add(obj);
        }

        System.out.println("After Insert List is " + list);
        for (int i = 0; i < 5; i++) {
            A prObj = (A) list.get(i);
            System.out.println("Values are" + prObj.getA());
        }
    }
}

class A {
    int a;

    public int getA() {
        return a;
    }

    public void setA(int a) {
        this.a = a;
    }

}

```

If I initialize A's object inside the for loop then it will add five objects and also changes the attribute for the objects. Can anyone explain this behaviour