Java Reference
In-Depth Information
Self-Test Exercise
28. Suppose we replace
NumberCarrier anObject
with
Object anObject
in Display 13.11 . What would be the fi rst statement in the program to cause an
error message? Would it be a compiler error message or a run-time error message?
Chapter Summary
An interface is a property of a class that says what methods a class that implements
the interface must have.
An interface is defined the same way as a class is defined except that the keyword
interface is used in place of the keyword class and method bodies are replaced
by semicolons.
An interface may not have any instance variables, with one exception: An interface
may have defined constants. If you use the syntax for an instance variable in an inner
class, the variable is automatically a constant, not a real instance variable.
An inner class is a class defined within another class.
One simple use of an inner class is as a helping class to be used in the definition of
the outer class methods and/or instance variables.
A static inner class is one that is not associated with an object of the outer class . It must
include the modifier static in its class heading.
To create an object of a nonstatic inner class outside the definition of the outer class,
you must first create an object of the outer class and use it to create an object of the
inner class.
Answers to Self-Test Exercises
1. Yes to both. An interface is a type and can be used like any other type.
2. Yes. Any of the interface methods that it does not fully define must be made
abstract methods.
3. A derived class can have only one base class, but it can implement any number of
interfaces.
 
Search WWH ::




Custom Search