Java Reference
In-Depth Information
Private members of a base class are not visible in the derived class.
1.
Objects of an abstract class cannot be constructed.
2.
If the derived class fails to implement any inherited abstract method,
then the derived class becomes abstract. If this was not intended, a com-
piler error will result.
3.
Final methods may not be overridden. Final classes may not be extended.
4.
5.
Static methods use static binding, even if they are overridden in a
derived class.
Java uses static overloading and always selects the signature of an over-
loaded method at compile time.
6.
In a derived class, the inherited base class members should only be ini-
tialized as an aggregate by using the
super
method. If these members are
public or protected, they may later be read or assigned to individually.
7.
When you send a function object as a parameter, you must send a con-
structed object, and not simply the name of the class.
8.
Overusing anonymous classes is a common error.
9.
The
throws
list for a method in a derived class cannot be redefined to throw
an exception not thrown in the base class. Return types must also match.
10.
When a method is overridden, it is illegal to reduce its visibility. This is
also true when implementing interface methods, which by definition are
always
public
.
11.
All the chapter code is available online. Some of the code was presented in
stages; for those classes, only one final version is provided.
PersonDemo.java
The
Person
hierarchy and test program.
Shape.java
The abstract
Shape
class.
Circle.java
The
Circle
class.
Rectangle.java
The
Rectangle
class.
ShapeDemo.java
A test program for the
Shape
example.
Stretchable.java
The
Stretchable
interface.
StretchDemo.java
The test program for the
Stretchable
example.
NoSuchElementException.java
The exception class in Figure 4.19. This is
part of
weiss.util
.
ConcurrentModificationException.java
and
EmptyStackException.java
are also online.
Search WWH ::
Custom Search