Chapter 8 Inheritance and Polymorphism Prerequisites for Part Il er 5 Arrays hapter 6 Objects and classes hapter7 St You can cover GUI after Chapter 8 Chapter 8 Inheritance and Polymorphism >Chapter 11 Getting Started with GUI Programming Chapter 9 Abstract Classes and Interfaces Chapter 12 Event-Driven Programmin Chapter 10 Object-Oriented Modelin 切皆有缘起 Chapter 15 Exceptions and Assertions You can cover Exceptions and 1O after Chapter 8 hapter 16 Simple Input and Output Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 1 Chapter 8 Inheritance and Polymorphism Prerequisites for Part II Chapter 6 Objects and Classes Chapter 7 Strings Chapter 8 Inheritance and Polymorphism Chapter 5 Arrays Chapter 9 Abstract Classes and Interfaces Chapter 10 Object-Oriented Modeling Chapter 11 Getting Started with GUI Programming Chapter 12 Event-Driven Programming Chapter 15 Exceptions and Assertions Chapter 16 Simple Input and Output You can cover Exceptions and I/O after Chapter 8 You can cover GUI after Chapter 8 一切皆有缘起
Objectives To develop a subclass from a superclass through inheritance ($8.2) To invoke the superclass constructors and methods using the super keyword (§8.3) To override methods in the subclass(88.4) To explore the useful methods (equals(objectl, hash Codeo, toString@, finalized clone(, and getClassQ)in the Object class($8.,88. 11 Optional To comprehend polymorphism, dynamic binding, and generic programming (§86) To describe casting and explain why explicit downcasting is necessary($8.7) To understand the effect of hiding data fields and static methods($8.8 Optional) To restrict access to data and methods using the protected visibility modifier (§8.9) To declare constants, unmodifiable methods, and nonextendable class using the final modifier($8.10) To initialize data using initial ization blocks and distinguish between instance initialization and static initial ization blocks(s8.12 Optioanl) Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 2 Objectives To develop a subclass from a superclass through inheritance (§8.2). To invoke the superclass’s constructors and methods using the super keyword (§8.3). To override methods in the subclass (§8.4). To explore the useful methods (equals(Object), hashCode(), toString(), finalize(), clone(), and getClass()) in the Object class (§8.5, §8.11 Optional). To comprehend polymorphism, dynamic binding, and generic programming (§8.6). To describe casting and explain why explicit downcasting is necessary (§8.7). To understand the effect of hiding data fields and static methods (§8.8 Optional). To restrict access to data and methods using the protected visibility modifier (§8.9). To declare constants, unmodifiable methods, and nonextendable class using the final modifier (§8.10). To initialize data using initialization blocks and distinguish between instance initialization and static initialization blocks (§8.12 Optioanl)
Introduction o Object-oriented programming ○ Inheritance o Software reusability o Classes are created from existing ones Absorbing attributes and behaviors Adding new capabilities pOlymorphism o Enables developers to write programs in general fashion o Helps add new capabilities to system Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 3 Introduction ⚫Object-oriented programming Inheritance ⚫Software reusability ⚫Classes are created from existing ones • Absorbing attributes and behaviors • Adding new capabilities Polymorphism ⚫Enables developers to write programs in general fashion ⚫Helps add new capabilities to system
Introduction(cont o Object-oriented programming ○ Inheritance e Subclass inherits from superclass Subclass usually adds instance variables and methods o Single vS. multiple inheritance Java does not support multiple inheritance Interfaces(discussed later)achieve the same effect o“Isa” relationship COmposition “Hasa” relationship Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 4 Introduction (cont.) ⚫Object-oriented programming Inheritance ⚫Subclassinherits from superclass • Subclass usually adds instance variables and methods ⚫Single vs. multiple inheritance • Java does not support multiple inheritance Interfaces (discussed later) achieve the same effect ⚫“Is a” relationship Composition ⚫“Has a” relationship
Object relationships Composition Whole-part -Existance of an object relies on another VideoStore Customer VideoRented Transaction# Name Date VideoRented Videoltem Videoltem Stock Title ating Liang, Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 5 Object relationships Composition •Whole-part –Existance of an object relies on another