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?
Consider the following code fragment:
Room office = new Room();
Room classroom = new Room();
office.setArea(125.0);
classroom.setArea(350.0);
office = classroom;
classroom.setArea(200.0);
Which of the following will be true, after this code executes? (Assume all classes and methods have been defined elsewhere correctly.)
Constant (final) variables in Java can be...
Suppose the following method is defined in some class:
public int someMethod(int x) { return x + z; }
Assume that the rest of the surrounding class has been defined correctly, and that z is the name of a static field variable in that class.
What, if anything, is wrong with this code?
Consider the following partial code for some Java class:
public class Person
{
public static final int maxPeople = 10;
public Person()
{
/* ... rest of class continues here... */
Assume the remainder of the class is defined correctly. What, if anything, is the biggest problem with this portion of code?
Consider the following partial code for some Java class:
public class Person
{
public static final int MAX_PEOPLE;
public Person()
{
/* ... rest of class continues here... */
Assume the remainder of the class is defined correctly. What, if anything, is the biggest problem with this portion of code?