I\'m having trobule writing a simple program in java.
I have a class called ticket, where I have:
public class Ticket {
public String movieTitle = null;
I think it is because you are using wrapper classes, i.e. Integer
instead of int
, which means that inside the class field you are only storing the reference. That means that in your constructor you are actually linking each class' currentMovieNumber
to the static movieNumber
so that when you increment the movieNumber
, since all the instances' numbers point to it, every Ticket
will have the same incremented number.
Using int
instead of Integer
should solve this.