Python First Edition STARTING OUT WITH Chapter 10 Inheritance

Slides:



Advertisements
Similar presentations
Copyright © 2012 Pearson Education, Inc. Chapter 15: Inheritance, Polymorphism, and Virtual Functions.
Advertisements

OOP: Inheritance By: Lamiaa Said.
Copyright © 2012 Pearson Education, Inc. Chapter 4 Inheritance and Polymorphism.
Dale Roberts Object Oriented Programming using Java - Inheritance Overview Dale Roberts, Lecturer Computer Science, IUPUI
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics (inheritance review + Java generics)
Copyright © 2004 Pearson Education, Inc.. Chapter 4 Enhanced Entity- Relationship and UML Modeling.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java: Early Objects Third Edition by Tony Gaddis Chapter.
Inheritance, Polymorphism, and Virtual Functions
2-1 © Prentice Hall, 2004 Chapter 2: Introduction to Object Orientation (Adapted) Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra,
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2007.
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
Chapter 11 Inheritance and Composition. Chapter Objectives Learn about inheritance Learn about subclasses and superclasses Explore how to override the.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Java Inheritance.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 11 Inheritance.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
Object-Oriented Design Justin Callanan CS 597. Object-Oriented Basics ● Data is stored and processed in “objects” ● Objects represent generalized real.
Inheriatance. 9-2 What is Inheritance? Generalization vs. Specialization Real-life objects are typically specialized versions of other more general objects.
Copyright © 2012 Pearson Education, Inc. Chapter 15: Inheritance, Polymorphism, and Virtual Functions.
11-2  What Is Inheritance?  Calling the Superclass Constructor  Overriding Superclass Methods  Protected Members  Chains of Inheritance  The Object.
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Polymorphism.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
© 2007 Lawrenceville Press Slide 1 Chapter 9 Inheritance  One class is an extension of another.  Allows a class to define a specialized type of an existing.
Java Software Solutions Lewis and Loftus Chapter 8 Copyright 1997 by John Lewis and William Loftus. All rights reserved. 1 Inheritance -- Introduction.
Inheritance Chapter 11 in Gaddis. Is a relationships in ‘real’ life Exist when one object is a specialized version of another one –Examples An english.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Chapter 4_part2: The Enhanced Entity-Relationship (EER) Model.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
2-1 © Prentice Hall, 2004 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.
Chapter 11 Polymorphism. Contents I. Polymorphism 1. Polymorphism 2. Polymorphism and Dynamic Binding 3. The “is-a” Relationship Does Not Work in Reverse.
Chapter 11 Inheritance. Contents I.What Is Inheritance? II. Calling the Superclass Constructor III. Overriding Superclass Methods IV. Protected Members.
Class Inheritance Part II: Overriding and Polymorphism Corresponds with Chapter 10.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Inheritance and Polymorphism
Programming in Java: lecture 7
Modern Programming Tools And Techniques-I
Class Inheritance Part I
Polymorphism.
Advanced Java Topics Chapter 9
Advanced Object-Oriented Programming
Interface, Subclass, and Abstract Class Review
Polymorphism, Abstract Classes & Interfaces
One class is an extension of another.
Object-Oriented Programming: Inheritance
Enhanced ER Modeling Transparencies
by Tony Gaddis and Godfrey Muganda
An Introduction to Inheritance
Object-Oriented Programming: Polymorphism
An introduction to inheritance
One class is an extension of another.
Starting Out with Java: From Control Structures through Objects
Figure 8.1 Inheritance: Relationships among timepieces.
Advanced Java Programming
Domain Class Diagram Chapter 4 Part 2 pp
Inheritance, Polymorphism, and Interfaces. Oh My
Chapter 9: Polymorphism and Inheritance
Advanced Java Topics Chapter 9
Inheritance, Polymorphism, and Virtual Functions
Advanced Programming Behnam Hatami Fall 2017.
Polymorphism, Abstract Classes & Interfaces
Object Oriented Programming: Inheritance
Java Programming, Second Edition
Inheritance: Introduction
Inheritance.
Chapter 9 Carrano Chapter 10 Small Java
Chapter 11: Inheritance Starting Out with Java: From Control Structures through Objects Third Edition by Tony Gaddis.
Figure 8.1 Inheritance: Relationships among timepieces.
Presentation transcript:

Python First Edition STARTING OUT WITH Chapter 10 Inheritance by Tony Gaddis

10.1 Introduction to Inheritance Concept: Inheritance allows a new class to extend an existing class. The new class inherits the members of the class it extends.

10.1 Introduction to Inheritance Inheritance and the “Is a” Relationship An “is a” relationship exists between objects. This means that the specialized object has all of the characteristics of the general object, plus additional characteristics that make it special. A poodle is a dog A car is a vehicle A flower is a plant A rectangle is a shape A football player is an athlete

10.1 Introduction to Inheritance Inheritance and the “Is a” Relationship Superclass (base class)– general class Subclass (derived class) – specialized class Inherits attributes and methods from the superclass without any of them having to be rewritten

10.1 Introduction to Inheritance Inheritance and the “Is a” Relationship Program 10-1 (Lines 1 through 44 of vehicles.py)

10.1 Introduction to Inheritance Inheritance and the “Is a” Relationship Program 10-2 (Lines 45 through 72 of vehicles.py)

10.1 Introduction to Inheritance Inheritance and the “Is a” Relationship Program 10-3 (car_demo.py)

10.1 Introduction to Inheritance Inheritance in UML Diagrams Figure 10-2 UML diagram showing inheritance

10.2 Polymorphism Concept: Polymorphism allows subclasses to have methods with the same names as methods in their superclasses. It gives the ability for a program to call the correct method depending on the type of object that is used to call it.

10.2 Polymorphism Polymorphism refers to an object’s ability to take different forms. Behaviors: The ability to define a method in a superclass, and then define a method with the same name in a subclass. When a subclass method has the same name as a superclass method, it is often said that the subclass method overrides the superclass method. The ability to call the correct version of an overridden method, depending on the type of object that is used to call it. If a subclass object is used to call an overridden method, then the subclass’s version of the method is the one that will execute. If a superclass object is used to call an overridden method, then the superclass’s version of the method is the one that will execute.

10.2 Polymorphism Program 10-10 (polymorphism_demo.py)

isinstance(object, ClassName) 10.2 Polymorphism The isinstance Function Is used to determine whether an object is an instance of a specific class or a subclass of that class isinstance(object, ClassName)

10.2 Polymorphism The isinstance Function Program 10-12 (polymorphism_demo2.py)

Chapter 10 Inheritance QUESTIONS ?