Java Reference
In-Depth Information
the old problem, but leave the outline in place. That is, keep the panel, text field,
event listener, and so on. Fill in the code for your new calculations. Finally,
rename classes, buttons, frame titles, and so on.
Once you understand the principles behind event listeners, frames, and panels,
there is no need to rethink them every time. Reusing the structure of a working
program makes your work more efficient.
However, reuse by Ȓcopy and renameȓ is still a mechanical and somewhat
error-prone approach. It is even better to package reusable program structures into
a set of common classes. The inheritance mechanism lets you design classes for
reuse without copy and paste.
487
488
CHAPTER SUMMARY
1. Inheritance is a mechanism for extending existing classes by adding methods
and fields.
2. The more general class is called a superclass. The more specialized class that
inherits from the superclass is called the subclass.
3. Every class extends the Object class either directly or indirectly.
4. Inheriting from a class differs from implementing an interface: The subclass
inherits behavior and state from the superclass.
5. One advantage of inheritance is code reuse.
6. When defining a subclass, you specify added instance fields, added methods,
and changed or overridden methods.
7. Sets of classes can form complex inheritance hierarchies.
8. A subclass has no access to private fields of its superclass.
9. Use the super keyword to call a method of the superclass.
10. To call the superclass constructor, you use the super keyword in the first
statement of the subclass constructor.
11. Subclass references can be converted to superclass references.
Search WWH ::




Custom Search