When I assign the value++ of a static int to another int, it is performing the assignments in an order that doesn’t seem to follow the order of operations for Java. Shouldn’t it do the ++ before the =?
public class Book
{
private int id;
private static int lastID = 0;
public Book ()
{
id=lastID++;
}
}
In the first book I construct, the id is 0. Shouldn’t it be 1 since lastID++ should happen first?
–> Yes
++is evaluated first as below :Your expression :
is equivalent to following expression
So you have
id as 0, you should use, pre-increament operator(++) in this case as :