Question: Suppose you have a Java class, Student, which needs to keep track of an ID number for each student object that is created. This ID

Suppose you have a Java class, Student, which needs to keep track of an ID number for each student object that is created. This ID number needs to be different for each student, but once it has been assigned to a particular student, its value should not be changed.
What is the best way of defining and initialising the ID variable?
Question 10Answer
a.
As a constant instance variable, i.e.,private final int ID, whose value is set by the class constructor.
b.
As a non-final instance variable, i.e.,private int ID, whose value is set by the class constructor.
c.
As a constant class variable, i.e., public static final int ID =12345678;
d.
As a non-final class variable, i.e.,private static int ID, whose value is set by the class constructor.
Clear my choice

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!