9.5. Overriding vs. Overloading

 
[Page 301]

Chapter 9. Inheritance and Polymorphism

Mayan God Shel, Mexico. Photographer: Philip Coblentz. Courtesy Brand X Pictures.

Objectives

  • To develop a subclass from a superclass through inheritance ( §9.2).

  • To invoke the superclass's constructors and methods using the super keyword ( §9.3).

  • To override methods in the subclass ( §9.4).

  • To distinguish differences between overriding and overloading ( §9.5).

  • To explore the useful methods ( equals(Object) , hashCode() , toString() , finalize() , clone() , and getClass() ) in the Object class ( §9.6, §9.13 Optional).

  • To comprehend polymorphism, dynamic binding, and generic programming ( §9.7).

  • To describe casting and explain why explicit downcasting is necessary ( §9.8).

  • To store, retrieve, and manipulate objects in an ArrayList ( §9.9).

  • To implement a Stack class using ArrayList ( §9.10).

  • To restrict access to data and methods using the protected visibility modifier ( §9.11).

  • To declare constants, unmodifiable methods, and nonextendable classes using the final modifier ( §9.12).

  • (Optional) To understand the effect of hiding data fields and static methods ( §9.14).

  • (Optional) To initialize data using initialization blocks and to distinguish between instance initialization and static initialization blocks ( §9.15).

  • (Optional GUI) To use inheritance in GUI programming ( §9.16).


[Page 302]

9.1. Introduction

Object-oriented programming allows you to derive new classes from existing classes. This is called inheritance . Inheritance is an important and powerful concept in Java. In fact, every class you define in Java is inherited from an existing class, either explicitly or implicitly. The classes you created in the preceding chapters were all extended implicitly from the java.lang.Object class.

This chapter introduces the concept of inheritance. Specifically, it discusses superclasses and subclasses, the use of the keyword super , and the Object class, explores polymorphism and dynamic binding, generic programming, and casting objects, and introduces the modifiers protected and final .

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net