hey and happy new year!
i cant understand whats the difference between x++ and ++x
if anyone knows let me know :)

thanks in advance !

With x++, the value of x is evaluated before the increment. With ++x, it is evaluated after.

int x=0;
System.out.println(x++); // prints 0, x now = 1
System.out.println(++x); // prints 2, x now = 2

Ezzaral gave quite a nice example. x++ is known as a prefix increment and ++x is a postfix increment. Most commonly you will use a prefix increment (loops and such) ie., for(int i=0;i < 10;i++)

public class Inheritance {

double width;
double height;
double deph;



Inheritance(double w, double h, double x)
width = y;
height = h;
depth = d;
void volume();
class extend1 extends box
double weight;


extend1(double w, double h, double d, double m)
weight = m;

public static void main(String args[]);{

extend one = new extend1(14,11,12,15);
extend1 two = new extend1(18,13,12,15);

System.out.println("weight of one is "  one.weight);
System.out.println("weight of two is "  two.weight);



Edited 3 Years Ago by happygeek: fixed formatting

x++ is known as a prefix increment and ++x is a postfix increment.

Actually it's the other way around :)
pre == before
post == after

This question has already been answered. Start a new discussion instead.