Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Lecture Java: Chapter 9 focuses on deriving new classes from existing classes, the protected modifier, creating class hierarchies, abstract classes, indirect visibility of, inherited members, Overloading. | Copyright © 2012 Pearson Education, Inc. Chapter 9 Inheritance Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus Inheritance Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 9 focuses on: deriving new classes from existing classes the protected modifier creating class hierarchies abstract classes indirect visibility of inherited members Overloading 8-2 Outline 8-3 Creating Subclasses Overriding Methods Class Hierarchies Inheritance and Visibility Designing for Inheritance Inheritance Inheritance allows a software developer to derive a new class from an existing one The existing class is called the parent class, or superclass, or base class The derived class is called the child class or subclass As the name implies, the child inherits characteristics of the parent That is, the child class inherits the methods and data defined by the parent class 8-4 Inheritance Inheritance . | Copyright © 2012 Pearson Education, Inc. Chapter 9 Inheritance Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus Inheritance Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 9 focuses on: deriving new classes from existing classes the protected modifier creating class hierarchies abstract classes indirect visibility of inherited members Overloading 8-2 Outline 8-3 Creating Subclasses Overriding Methods Class Hierarchies Inheritance and Visibility Designing for Inheritance Inheritance Inheritance allows a software developer to derive a new class from an existing one The existing class is called the parent class, or superclass, or base class The derived class is called the child class or subclass As the name implies, the child inherits characteristics of the parent That is, the child class inherits the methods and data defined by the parent class 8-4 Inheritance Inheritance relationships are shown in a UML class diagram using a solid arrow with an unfilled triangular arrowhead pointing to the parent class 8-5 Vehicle Car Proper inheritance creates an is-a relationship, meaning the child is a more specific version of the parent Inheritance A programmer can tailor a derived class as needed by adding new variables or methods, or by modifying the inherited ones Software reuse is a fundamental benefit of inheritance By using existing software components to create new ones, we capitalize on all the effort that went into the design, implementation, and testing of the existing software 8-6 Deriving Subclasses In Java, we use the reserved word extends to establish an inheritance relationship 8-7 See Words.java (page 382) See Book.java (page 385) See Dictionary.java (page 386) class Car extends Vehicle { // class contents } The protected Modifier Visibility modifiers affect the way that class members can be used in a child class Variables and methods declared with .