Chapter 13: Interfaces and Inner Classes
Multiple Choice
1) A Java interface is an example of:
(a) encapsulation
(b) abstraction
(c) polymorphism
(d) all of the above
2) A class that uses an interface must use the keyword:
(a) Extends
(b) Inherits
(c) Super
(d) Implements
3) An interface and all of its method headings are normally declared to be:
(a) public
(b) private
(c) protected
(d) package access
4) In Java, a derived class can have ______base class(es).
(a) one
(b) two
(c) three
(d) there is no limit
5) A class that implements an interface but only gives definitions for some of the method headings given in the interface is called a/an:
(a) concrete class
(b) abstract class
(c) discrete class
(d) friendly class
6) The method that must be implemented in a class using the Comparable interface is:
(a) public Object compareTo(Object other)
(b) public Boolean compareTo(Object other)
(c) public int compareTo(Object other)
(d) none of the above
7) The Comparable interface is in the ______package.
(a) java.util
(b) java.io
(c) java.awt
(d) java.lang
8) The compareTo method should return ______if the calling object equals the parameter.
(a) A negative number
(b) Zero
(c) A positive number
(d) Null
9) An interface may contain:
(a) instance variables
(b) primitive variables
(c) constant variables
(d) all of the above
10) Any constant variables defined in an interface must be defined as:
(a) public
(b) private
(c) protected
(d) package access
11) When using the clone method from an inherited base class you should account for a ______exception.
(a) CloneNotFoundException
(b) CloneEmptyException
(c) CloneNotSupportedException
(d) CloneNotEmptyException
n True/False
1) Java interfaces are a way of simulating multiple inheritance.
2) An interface specifies the headings and definitions for methods that must be defined in any class that implements the interface.
3) A class may only implement one interface.
4) An interface is a type.
5) You can not derive an interface from a base interface.
6) The compiler and the run-time system enforces semantics on the Comparable interface.
7) An interface can contain defined constants as well as method headings or instead of method headings.
n Short Answer/Essay
1) What are the obligations of a class that implements a specific interface?
2) What are the semantics of the Comparable interface?
3) What are the rules of total ordering?
4) Why does Java only allow the inheritance of only one base class?