0

Suppose I have A mutable class called Person.
What I want to do is to initialize several variables of Person at once.
Trying using

Person a,b,c,d;
a=b=c=d=new Person();

would necessarily point all of them to a same memory location. How can I initialize them at once? I don't want to use array or ArrayList.

Mehrdad Shokri
  • 1,974
  • 2
  • 29
  • 45
  • 1
    This question can help you: [Initializing multiple variables to the same value in Java](http://stackoverflow.com/questions/6202818/initializing-multiple-variables-to-the-same-value-in-java) – CloudPotato Jun 01 '16 at 10:09
  • Why don't you create an array of type `Person[]`. Then you can initialize them all in a loop. – mikeyq6 Jun 01 '16 at 10:12
  • @Blobonator I had seen that question already, but thought there might be a better way – Mehrdad Shokri Jun 01 '16 at 10:33

0 Answers0