An Introduction to Specialization/Generalization and Inheritance
With Examples in Java |
Prof. David Bernstein
|
Computer Science Department |
bernstdh@jmu.edu |
private
members in the superclass
protected
#
extends
in the declaration of the classsuper
as the left-side operand of the
.
operator to eliminate ambiguity (if needed)super()
(which must be the
first statement in a constructor of the subclass) super()
is called explicitly,
the default constructor in the superclass will be called
(so, if there isn't one, the subclass won't compile)super()
is called explicitly,
the default constructor in the superclass will be called
(so, if there isn't one, the subclass won't compile).class
file) for an existing class.java
file) for an existing class but don't want to change it
@Override
super.
Chirp
is not an ExpandedChirp
and methods might be called on e
that it
doesn't have
ClassCastException
will be thrown
final
can't be overridden by a subclassfinal
can't be specialized (i.e., a class that extends
a final
class will not compile){leaf}
after the return type{leaf}
after the nameassertEquals()
works
with int
values,
double
values, objects, etc...printf()
method in
the PrintWriter
class is passed a format
string and then a variable number of arguments of any typeassertEquals()
is overloaded and one of the versions
has Object
parametersprintf()
are String
and Object...