Home » Java » Incorrect value shows up when I update an objects value [on hold]

Incorrect value shows up when I update an objects value [on hold]

Posted by: admin June 30, 2018 Leave a comment

Questions:

I have a class Car that has a field mileage. When I update the field and print, I still incorrect value showing up.

class Car{

    public int mileage;

    public static void main(String[] args){
        Car c1 = new Car();
        Car c2 = new Car();
        c1.mileage = 1000;
        System.out.println(c2.mileage);
    }
}

I am expecting to see 1000 but see 0 instead.

Answers: