Professional Documents
Culture Documents
◦ Existing class is called the superclass, base class, ancestor, or parent class
◦ New class is the subclass, derived class, descendant, or child class
◦ If you don’t explicitly specify which class a new class extends, the
class extends Object implicitly.
◦ Indicates that a method should override a superclass method with the same
signature.
◦ If it does not, a compilation error occurs.
◦ Even though @Override is optional, use it to avoid finding errors at runtime as
opposed to compile-time.
◦ Java is a strongly typed language which usually means many errors are found
at compile-time rather than run-time.
◦ It’s always better to find errors earlier rather than later!!
In fact, there are hidden slides that do just that – what a waste of time
and energy!
If you find yourself cutting and pasting code over and over, create a
common base class and reuse the code that way.
If the subclass does not invoke the superclass’s constructor explicitly, the
compiler will call the superclass’s default constructor.
◦ Class CommissionEmployee does not have such a constructor, so the
compiler would issue an error.
With protected instance variables, the subclass gets access to the instance
variables, but classes that are not subclasses and classes that are not in the
same package cannot access these variables directly.
composition
part of the class’s implementation details that are hidden from the
class’s client code
If the reference’s class type changes, you may need to make changes to
the composing class’s internal details, but those changes do not affect
the client code
CommissionEmployee–BasePlusCommissionEmployee hierarchy
using composition, rather than inheritance.
Exercise 9.16 asks you to reimplement the hierarchy using a