ing constructor in a class, xMethod() is _________ in the class.
public MyClass() {
xMethod();
}
a. an instance method
b. a static method or an instance method
c. a static method
#
17. To declare a constant MAX_LENGTH as a member of the class, you write
a. final double MAX_LENGTH = 99.98;
b. final static double MAX_LENGTH = 99.98;
c. final static MAX_LENGTH = 99.98;
d. static double MAX_LENGTH = 99.98;
e. final static float MAX_LENGTH = 99.98;
#
18. Which of the following statements are true?
a. The default constructor is a no-arg constructor.
b. At least one constructor must always be defined explicitly.
c. A default constructor is provided automatically if no constructors are explicitly declared in the class.
d. Every class has a default constructor.
#
19. You use underline to denote static variables and methods.
a. false
b. true
#
20. You use the plus sign (+) to denote public data or methods.
a. true
b. false
#
21. What is the output of the following program?
import java.util.Date;
public class Test {
public static void main(String[] args) {
Date date = new Date(1234567);
m1(date);
System.out.print(date.getTime() + " ");
m2(date);
System.out.println(date.getTime());
}
public static void m1(Date date) {
date = new Date(7654321);
}
public static void m2(Date date) {
date.setTime(7654321);
}
}
a. 1234567 7654321
b. 7654321 7654321
c. 7654321 1234567
d. 1234567 1234567
#
22. Analyze the following code:
public class Test {
public static void main(String args[]) {
NClass nc = new NClass();
nc.t = nc.t++;
}
}
class NClass {
int t;
private NClass() {
}
}
a. The program has a compilation error because the NClass class has a private constructor.
b. The program compiles, but has a runtime error because t has no initial value.
c. The program compiles and runs fine.
d. The program does not compile because the parameter list of the main method is wrong.
#
23. Which of the following statement is most accurate?
a. A reference variable is an object.
b. An object may contain the references of other objects.
c. A reference variable refers to an object.
d. An object may contain other objects.
#
24. Suppose you wish to provide an accessor method for a boolean property finished, what signature of the method should be?
a. public void getFinished()
b. public boolean isFinished()
c. public void isFinished()
d. public boolean getFinished()
#
25. Suppose TestCircle1 and Circle1 in Listing 8.1 are in two separate files named TestCircle1.java and Circle1.java, respectively. What is the outcome of compiling TestCircle.java and then Circle
.java?
a. Both compile fine.
b. Only TestCircle1.java compiles.
c. Neither compiles successfully.
d. Only Circle1.java compiles.
#