Why changing variable of one object reflect in another object in below code while both are separate memory

It rather looks like that because you initialized A in the same statement as you declared it, the compiler has taken A to be a static variable. Sure behaves like one. I would try removing the initialization (= 5) from the declaration of A. If you want all object of this class to start with a value of 5 for A, add an initial block and initialize A to that value there.