Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Final keyword

pavitranpavitran MalaysiaPosts: 1

public class add {
private final int NUMBER;
public add(int x){ NUMBER = x;}
}

public class Final {
public static void main(String[] args) {
add addingTen = new add(10);
add addingEleven = new add(11);
System.out.println(addingTen);
System.out.println(addingEleven);
System.out.println(addingTen);
}
}

OUTPUT : sum = 10 sum = 11 sum = 10 //why does the NUMBER variable still change although i declared it as final?

Comments

  • B00B00 Posts: 91 ✭✭✭

    It does not change, addingTen and addingEleven are different objects each with their own initial value.

Sign In or Register to comment.