Java Homework Questions 10 Multiple Choice Questions QUESTIO
Java Homework Questions: 10 Multiple Choice Questions
QUESTION 1: The Comparable interface is implemented by some class and alpha and beta are objects of that class. Under what circumstance will alpha.compareTo(beta) return a negative integer?
A) alpha comes before beta.
B) alpha comes after beta.
C) alpha and beta refer to the same object.
D) alpha is equivalent to beta but they reference different objects.
QUESTION 2: Which of the following is true about an abstract base class?
A) no constructors should be provided
B) at least one member function should be abstract
C) no objects of the class can be created
D) Both (b) and (c) are true
E) Only (c) is true.
QUESTION 3: When is a method abstract?
A) When it is constant throughout the inheritance hierarchy
B) Its definition changes in the inheritance hierarchy, but there is a reasonable default
C) No reasonable default can be provided, and it must be defined in the inheritance hierarchy
D) Always
E) none of the above
QUESTION 4: Which clause is used to derive a new class?
A) extends
B) implements
C) import
D) throw
E) (a) and (b)
QUESTION 5: In the derived class, which data members of the base class are visible?
A) those declared as public only
B) those declared as protected only
C) those declared as public or protected
D) those declared as public or private
E) all data members are visible
QUESTION 6: Which term describes the practice of protecting data within a class?
A) abstraction
B) static binding
C) polymorphism
D) composition
E) encapsulation
QUESTION 7: Which of the following are not allowed in an interface?
A) public methods
B) static methods
C) final methods
D) public fields
E) static fields
QUESTION 8: Which term describes the ability of a reference type to reference objects of several different types?
A) composition
B) encapsulation
C) information hiding
D) polymorphism
E) static binding
QUESTION 9: For which methods is dynamic binding used?
A) all class methods
B) all static methods
C) final methods
D) non-static, non-final class methods
E) none of the above
QUESTION 10: Which of the following is false?
A) An abstract class may implement an interface.
B) A class that contains an abstract method must be declared abstract itself or a compiler message will result.
C) A class may implement multiple interfaces.
D) A class that extends another class may implement only one interface.
E) An interface may extend another interface.
Solution
QUESTION 1:
A) alpha comes before beta.
QUESTION 2:
D) Both (b) and (c) are true
QUESTION 3:
C) No reasonable default can be provided, and it must be defined in the inheritance hierarchy
QUESTION 4:
E) (a) and (b)
QUESTION 5:
C) those declared as public or protected
QUESTION 6:
E) encapsulation
QUESTION 7:
C) final methods
QUESTION 8
D) polymorphism
QUESTION 9:
D) non-static, non-final class methods
QUESTION 10:
E) An interface may extend another interface.

