JAVA CH8 EXAMINATION
QUESTIONS WITH CORRECT
ANSWERS
8.9 Q1: enum types are implicitly ________ and enum constants are implicitly
________.
a. a. final, static.
b. b. static, static.
c. c. static, final.
d. d. final, final.
. - Answer- ANS: a. final, static
8.9 Q2: Which statement is false?
a. a. An enum declaration is a comma-separated list of enum constants and may
optionally include other components of traditional classes, such as constructors, fields
and methods.
b. b. Any attempt to create an object of an enum type with operator new results in a
compilation error.
c. c. An enum constructor cannot be overloaded.
d. d. An enum constructor can specify any number of parameters. - Answer- ANS: c. An
enum constructor cannot be overloaded.
8.9 Q3: Which method returns an array of the enum's constants?
a. a. values.
b. b. getValues.
c. c. constants.
d. d. getConstants. - Answer- ANS: a. values.
8.10 Q1: Which of the following is false?
a. a. Method finalize does not take parameters and has return type void.
b. b. Memory leaks using Java are rare because of automatic garbage collection.
c. c. Objects are marked for garbage collection by method finalize.
d. d. The garbage collector reclaims unused memory. - Answer- ANS: c. Objects are
marked for garbage collection by method finalize. (Objects are marked for garbage
collection when there are no more references to the object).
8.11 Q1: Static class variables:
a. a. are final.
b. b. are public.
c. c. are private.
, d. d. are shared by all objects of a class. - Answer- ANS: d. are shared by all objects of
a class.
8.11 Q2: Which of the following is false?
a. a. A static method must be used to access private static instance variables.
b. b. A static method has no this reference.
c. c. A static method can be accessed even when no objects of its class have been
instantiated.
d. d. A static method can call instance methods directly. - Answer- d. d. A static method
can call instance methods directly.
8.12 Q1: Which syntax imports all static members of class Math?
a. a. static import java.lang.Math.*.
b. b. import static java.lang.Math.*.
c. c. static import java.lang.Math.
d. d. import static java.lang.Math. - Answer- ANS: b. import static java.lang.Math.*.
8.13 Q1: Instance variables declared final do not or cannot:
a. a. Cause syntax errors if used as a left-hand value.
b. b. Be initialized.
c. c. Be modified.
d. d. None of the above. - Answer- ANS: c. Be modified.
8.13 Q2: A final field should also be declared ________ if it is initialized in its
declaration.
a. a. private.
b. b. public.
c. c. protected.
d. d. static. - Answer- ANS: d. static.
8.16 Q1: A package is:
a. a. A directory structure used to organize classes and interfaces.
b. b. A mechanism for software reuse.
c. c. A group of related classes and interfaces.
d. d. All of the above. - Answer- ANS: d. All of the above.
8.16 Q2: A class within a package must be declared public if
a. a. It will be used only by other classes in the same package.
b. b. It will be used by classes that are not in the same package.
c. c. It is in the same directory as the other classes in the package.
d. d. It has a unique name. - Answer- ANS: b. It will be used by classes that are not in
the same package. Classes outside the package cannot use a class if the class is not
declared public.
QUESTIONS WITH CORRECT
ANSWERS
8.9 Q1: enum types are implicitly ________ and enum constants are implicitly
________.
a. a. final, static.
b. b. static, static.
c. c. static, final.
d. d. final, final.
. - Answer- ANS: a. final, static
8.9 Q2: Which statement is false?
a. a. An enum declaration is a comma-separated list of enum constants and may
optionally include other components of traditional classes, such as constructors, fields
and methods.
b. b. Any attempt to create an object of an enum type with operator new results in a
compilation error.
c. c. An enum constructor cannot be overloaded.
d. d. An enum constructor can specify any number of parameters. - Answer- ANS: c. An
enum constructor cannot be overloaded.
8.9 Q3: Which method returns an array of the enum's constants?
a. a. values.
b. b. getValues.
c. c. constants.
d. d. getConstants. - Answer- ANS: a. values.
8.10 Q1: Which of the following is false?
a. a. Method finalize does not take parameters and has return type void.
b. b. Memory leaks using Java are rare because of automatic garbage collection.
c. c. Objects are marked for garbage collection by method finalize.
d. d. The garbage collector reclaims unused memory. - Answer- ANS: c. Objects are
marked for garbage collection by method finalize. (Objects are marked for garbage
collection when there are no more references to the object).
8.11 Q1: Static class variables:
a. a. are final.
b. b. are public.
c. c. are private.
, d. d. are shared by all objects of a class. - Answer- ANS: d. are shared by all objects of
a class.
8.11 Q2: Which of the following is false?
a. a. A static method must be used to access private static instance variables.
b. b. A static method has no this reference.
c. c. A static method can be accessed even when no objects of its class have been
instantiated.
d. d. A static method can call instance methods directly. - Answer- d. d. A static method
can call instance methods directly.
8.12 Q1: Which syntax imports all static members of class Math?
a. a. static import java.lang.Math.*.
b. b. import static java.lang.Math.*.
c. c. static import java.lang.Math.
d. d. import static java.lang.Math. - Answer- ANS: b. import static java.lang.Math.*.
8.13 Q1: Instance variables declared final do not or cannot:
a. a. Cause syntax errors if used as a left-hand value.
b. b. Be initialized.
c. c. Be modified.
d. d. None of the above. - Answer- ANS: c. Be modified.
8.13 Q2: A final field should also be declared ________ if it is initialized in its
declaration.
a. a. private.
b. b. public.
c. c. protected.
d. d. static. - Answer- ANS: d. static.
8.16 Q1: A package is:
a. a. A directory structure used to organize classes and interfaces.
b. b. A mechanism for software reuse.
c. c. A group of related classes and interfaces.
d. d. All of the above. - Answer- ANS: d. All of the above.
8.16 Q2: A class within a package must be declared public if
a. a. It will be used only by other classes in the same package.
b. b. It will be used by classes that are not in the same package.
c. c. It is in the same directory as the other classes in the package.
d. d. It has a unique name. - Answer- ANS: b. It will be used by classes that are not in
the same package. Classes outside the package cannot use a class if the class is not
declared public.