Howdy, Stranger!

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


Final keyword

pavitranpavitran MalaysiaMember Posts: 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);

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


  • B00B00 Member Posts: 115 ✭✭✭

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

Sign In or Register to comment.