One class is an extension of another.

Slides:



Advertisements
Similar presentations
Inheritance. Many objects have a hierarchical relationship –Examples: zoo, car/vehicle, card game, airline reservation system Inheritance allows software.
Advertisements

Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
OOP: Inheritance By: Lamiaa Said.
Copyright © 2012 Pearson Education, Inc. Chapter 4 Inheritance and Polymorphism.
1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
Chapter 10: Introduction to Inheritance
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
More about classes and objects Classes in Visual Basic.NET.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
LECTURE 07 Programming using C# Inheritance
Unit 5 School of Information Systems & Technology1 School of Information Systems and Technology (IST)
Inheritance using Java
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
Programming Pillars Introduction to Object- Oriented Programming.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Mark Fontenot CSE Honors Principles of Computer Science I Note Set 14.
AP Computer Science A – Healdsburg High School 1 Interfaces, Abstract Classes and the DanceStudio - Similarities and Differences between Abstact Classes.
Java Programming Dr. Randy Kaplan. Abstract Classes and Methods.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
Coming up: Inheritance
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
© 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.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Inheritance and Polymorphism
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
Chapter 9 Inheritance and Polymorphism. Object-oriented programming is based on a paradigm in which objects are used to model a specification. Objects.
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Inheritance and Polymorphism
Sections Inheritance and Abstract Classes
Lecture 12 Inheritance.
Data Structures and Algorithms
Inheritance AKEEL AHMED.
Chapter 3 Assignment Statement
Computing with C# and the .NET Framework
Can perform actions and provide communication
CSC 205 Java Programming II
One class is an extension of another.
Can perform actions and provide communication
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Inheritance, Polymorphism, and Interfaces. Oh My
Week 6 Object-Oriented Programming (2): Polymorphism
Interfaces.
Can perform actions and provide communication
Java Programming, Second Edition
Java Inheritance.
Object-Oriented Programming: Inheritance and Polymorphism
Chapter 14 Abstract Classes and Interfaces
Inheritance and Polymorphism
CIS 199 Final Review.
Chapter 8 Class Inheritance and Interfaces
Chapter 11 Inheritance and Polymorphism Part 1
Final and Abstract Classes
Chapter 11 Inheritance and Encapsulation and Polymorphism
Presentation transcript:

One class is an extension of another. 6/19/2018 7:37 AM Chapter 8 Inheritance One class is an extension of another. Allows a class to define a specialized type of an existing class. Classes that are derived from existing classes demonstrate an "is-a" relationship. A class "is a" type of another class. There can be multiple levels of inheritance. © 2012 EMC Publishing, LLC

Chapter 8 The Puck Class Hierarchy 6/19/2018 7:37 AM Chapter 8 The Puck Class Hierarchy The Puck class inherits the Disk class which inherits the Circle class. © 2012 EMC Publishing, LLC

Chapter 8 Subclass Terminology 6/19/2018 7:37 AM Chapter 8 Subclass Terminology A class that inherits another class is called the subclass. The class that is used to create the subclass is called the superclass. The subclass is also called the derived class. The superclass is also called the base class. © 2012 EMC Publishing, LLC

call to superclass constructor 6/19/2018 7:37 AM Chapter 8 A Subclass superclass subclass public class Disk extends Circle { private double thickness; public Disk(double r, double t) { super(r); thickness = t; } ... public String toString() { ... } call to superclass constructor Note: This slide contains animations. Press the space bar or click the mouse button to display each animation. This slide contains four (4) animations. A subclass, or derived class, declaration includes the subclass name. <press space bar> Following the subclass name is the keyword extends. After the keyword extends is the superclass, or base class, name. <press space bar> The constructor in a subclass often makes a call to the superclass constructor to initialize variables inherited from the base class. <press space bar> Superclass methods, such as toString(), can be redefined, or overridden, in the subclass. <press space bar> override of superclass method © 2012 EMC Publishing, LLC

6/19/2018 7:37 AM Chapter 8 Polymorphism OOP property in which objects have the ability to assume different types Based on inheritance A superclass object can reference an subclass object: Circle wafer; Disk cookie = new Disk(2, 0.5); wafer = cookie; //Circle can refer to Disk /* displays: The disk has radius 2.0 and thickness 0.5 */ System.out.println(wafer); © 2012 EMC Publishing, LLC

Chapter 8 The Music Application 6/19/2018 7:37 AM Chapter 8 The Music Application © 2012 EMC Publishing, LLC

Chapter 8 Abstract Classes 6/19/2018 7:37 AM Chapter 8 Abstract Classes Models an abstract concept Cannot be instantiated Declared with the keyword abstract Intended to be inherited © 2012 EMC Publishing, LLC

Chapter 8 Abstract Methods 6/19/2018 7:37 AM Chapter 8 Abstract Methods Member of an abstract class Declared with the keyword abstract Contains a method declaration but no body Implemented in a subclass © 2012 EMC Publishing, LLC

Chapter 8 An Abstract Class 6/19/2018 7:37 AM Chapter 8 An Abstract Class abstract class abstract class Instrument { ... abstract String makeSound(); } abstract method Note: This slide contains animations. Press the space bar or click the mouse button to display each animation. This slide contains two (2) animations. An abstract class is declared with the keyword abstract. <press space bar> Abstract classes are not used to instantiate objects. They model an abstract concept and are intended to be inherited. The derived class based on the abstract class then implements the specifics. Abstract classes often include abstract methods. <press space bar> An abstract method is also declared with the keyword abstract. It contains only a declaration and no body. The implementation of the abstract method is in a subclass. © 2012 EMC Publishing, LLC

A class with method declarations that have no implementations 6/19/2018 7:37 AM Chapter 8 Interfaces A class with method declarations that have no implementations Cannot be inherited Must be implemented in a class using the keyword implements Adds behavior to a class, but does not provide a hierarchy for the class A class can implement multiple interfaces © 2012 EMC Publishing, LLC