Java Reference
In-Depth Information
SR 9.12
The only Java class that does not have a parent class is the
Object
class.
As mentioned in the previous answer, all other classes are derived from
Object
either directly or indirectly.
Object
is the root of the Java inheri-
tance tree.
SR 9.13
An abstract class is a representation of a general concept. Common
characteristics and method signatures can be defined in an abstract class
so that they are inherited by child classes derived from it.
SR 9.14
It is a contradiction to define an abstract class as
final
. An abstract
class is “incomplete” because it contains abstract methods. Typically
the definitions of these methods are completed by one or more classes
that extend the abstract class. But a
final
class cannot be extended, so
there would be no way to complete its definition.
SR 9.15
A new interface can be derived from an existing interface using inheri-
tance, just as a new class can be derived from an existing class.
9.4
Visibility
SR 9.16
A class member is not inherited if it has private visibility, meaning that
it cannot be referenced by name in the child class. However, such mem-
bers do exist for the child and can be referenced indirectly.
SR 9.17
The
Pizza
class can refer to the variable servings explicitly, because it
is declared with
protected
visibility. It cannot, however, refer to the
calories
method explicitly, because the
calories
method is declared
as
private
.
9.5
Designing for Inheritance
SR 9.18
An inheritance derivation represents an “is-a” relationship when the
child class represents a more specific version of the parent class. For
example, a dictionary is a type of book, so if a
Dictionary
class extends
a
Book
class, the inheritance represents an “is-a” relationship.
SR 9.19
Common features of classes should appear as high as possible in a class
hierarchy, as long as it is appropriate for the features to be at the level
where they are defined. This approach supports understandability, con-
sistency, and reuse.
SR 9.20
You can define a class with multiple roles by having the class implement
more than one interface.
SR 9.21
You should override the
toString
method of a parent in its child class,
even when the method is not invoked through the child by your current
Search WWH ::
Custom Search