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 Answer
a
As a constant instance variable, ieprivate final int ID whose value is set by the class constructor.
b
As a nonfinal instance variable, ieprivate int ID whose value is set by the class constructor.
c
As a constant class variable, ie public static final int ID ;
d
As a nonfinal class variable, ieprivate 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
