/
Inheritance Examples Inheritance Examples

Inheritance Examples - PowerPoint Presentation

test
test . @test
Follow
358 views
Uploaded On 2016-02-28

Inheritance Examples - PPT Presentation

1 Realworld Examples Animals Source code httpenwikipediaorgwikiPolymorphisminobjectorientedprogramming Animal Dog Cat 2 3 Example 2 Timepieces Multiple inheritance A ID: 235007

inheritance human cat animal human inheritance animal cat dog java wiki examples interface animalactions base class group animals org wikipedia http objects

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Inheritance Examples" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Inheritance Examples

1Slide2

Real-world Examples: Animals

Source code:

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

Animal

Dog

Cat

2Slide3

3

Example #2: TimepiecesSlide4

Multiple inheritance

A

derived class can have more than one base class

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

4Slide5

Example #3: Shapes

Basic Shape

Circle

Polygon

Ellipse

Square

Hexagon

Rectangle

5Slide6

Example #4: Wireless Telephony

Mobile initiated message

Registration

Call Processing

SMS

Origination

Page Response

6Slide7

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.

7Slide8

Inheritance Examples in

Java and C++

8Slide9

Back to Example #1:

Animals

9

Animal

Dog

Cat

Want to group them together &

make them talk?Slide10

Concepts

Static

binding vs. dynamic binding

Polymorphism using virtual methodsAbstract base classAbility of base class pointers to point to derived class objects

10Slide11

Add Human?

11

Animal

Dog

Cat

Human

Want to group them together &

make them talk?Slide12

C++

12

Animal

Dog

Cat

Human

AnimalActionsSlide13

Java: Interface

13

Animal

Dog

Cat

Human

AnimalActionsSlide14

Example from Wiki:

Bad use of Inheritance

14

Parrot

Human

WhistlerSlide15

Example from Wiki

15

Whistler

Parrot

HumanSlide16

Concepts

Interface

16Slide17

C++

17

Animal

Dog

Cat

Human

AnimalActionsSlide18

Java: Interface

18

Animal

Dog

Cat

Human

AnimalActionsSlide19

Inheritance Examples in

Java and C++

19Slide20

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

20