Inheritance examples
This presentation is the property of its rightful owner.
Sponsored Links
1 / 20

Inheritance Examples PowerPoint PPT Presentation


  • 49 Views
  • Uploaded on
  • Presentation posted in: General

Inheritance Examples. Real-world Examples: Animals. Source code: http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming. Animal. Dog. Cat. Example #2: Timepieces. Multiple inheritance. A derived class can have more than one base class

Download Presentation

Inheritance Examples

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Inheritance examples

Inheritance Examples


Real world examples animals

Real-world Examples: Animals

Source code: http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming

Animal

Dog

Cat


Example 2 timepieces

Example #2: Timepieces


Multiple inheritance

Multiple inheritance

  • A derived class can have more than one base class

  • Java does not support it – uses “interface” instead.


Example 3 shapes

Example #3: Shapes

Basic Shape

Circle

Polygon

Ellipse

Square

Rectangle

Hexagon


Example 4 wireless telephony

Example #4: Wireless Telephony

Mobile initiated message

Registration

Call Processing

SMS

Origination

Page Response


Value of inheritance

Value of inheritance?

  • Helps us to break software into manageable pieces

  • Existing classes can be morphed to design new classes – code reuse

  • Enables us to group different types of objects together and do some action on all of them.


Inheritance examples in java and c

Inheritance Examples in Java and C++


Back to example 1 animals

Back to Example #1: Animals

Animal

Dog

Cat

Want to group them together &

make them talk?


Concepts

Concepts

  • Static binding vs. dynamic binding

  • Polymorphism using virtual methods

  • Abstract base class

  • Ability of base class pointers to point to derived class objects


Add human

Add Human?

Animal

Human

Dog

Cat

Want to group them together &

make them talk?


Inheritance examples

C++

AnimalActions

Animal

Human

Dog

Cat


Java interface

Java: Interface

AnimalActions

Animal

Human

Dog

Cat


Example from wiki bad use of inheritance

Example from Wiki:Bad use of Inheritance

Whistler

Parrot

Human


Example from wiki

Example from Wiki

Whistler

Human

Parrot


Concepts1

Concepts

  • Interface


Inheritance examples

C++

Animal

AnimalActions

Dog

Cat

Human


Java interface1

Java: Interface

AnimalActions

Animal

Human

Dog

Cat


Inheritance examples in java and c1

Inheritance Examples in Java and C++


References

References

  • http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming - Animals : Inheritance coding examples in Java/C++/…

  • http://en.wikipedia.org/wiki/Interface_%28Java%29 – Java Interfaces


  • Login