0

I want to create a java class with a data member say id such that each object has its own id but the object id is assigned during object creation and then it can not be modified later.

user3282758
  • 1,379
  • 11
  • 29

1 Answers1

5
public class Test {
  private final int id;

  public Test(int id) {
    this.id = id;
  }

}

A as final declared variable can only be initialized one time. At definition or at constructor.

Rene M.
  • 2,660
  • 15
  • 24