I have a class called Hand
and another class to test it.
Hand
uses global variables and change their values with some methods
if in class test I create
Make private List<Card> hand = new ArrayList<Card>();
as instance variable rather then make it static..
Coz static is property of class and instance variables are property of Object... which is different for different Object ..but in case of static they are same for all objects..
Turn the private static List<Card>
into a private List<Card>
.
The static
keyword makes the variable class-scoped, not instance-scoped. That means the same value is common for all instances of the class. A non-static member is particular to every instance of the class. Remove the static
keyword and you will get the desired behavior.
Remove the static
modifier which is common for all instance of the class loaded in a particular class loader.