Lecture08-Inheritance_Part_1

Lecture08-Inheritanc - Inheritance Part I 1 Computer Programming II Learninig Objectives l l l l l l l To understand the"is-a relationship To

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Programming II 1 Inheritance Part I
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Computer Programming II 2 Learninig Objectives l To understand the "is-a" relationship l To understand inheritance terminology l To understand how to draw Object Relationship Diagrams (ORD) l To understand how to define subclasses l To understand how to call superclass constructor l To understand multiple inheritance l To understand diamond inheritance and virtual inheritance
Background image of page 2
Computer Programming II 3 The "is-a" Relationship l Inheritance is also known as "is-a" relationship l Inheritance promotes code reuse and simplifies code maintenance l By nature we commonly group objects that have a common attributes and/or behaviors into classes/categories . l A few examples of classes are animals , stationery and human . l Under each of these classes there can be zero, one, or more subclasses/subcategories l Further, these subclasses can further be broken down into more specific classes
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Computer Programming II 4 Example 1/2 l Under the animal class , we can create three subclasses: bird , mammal and fish . l Animal, bird, mammal and fish are classes . l Bird, mammal and fish are subclasses of animal. l Eagle, parrot, whale, monkey, goldfish and shark are instances/objects . (They can actually be sub-subclasses.)
Background image of page 4
Computer Programming II 5 5 The "is-a" Relationship l Note the following statements: Eagle is a bird . Parrot is a bird . Both are also animals . Cat is a mammal . Monkey is a mammal . Both are also animals . Goldfish is a fish . Shark is a fish . Both are also animals . l A bird is different from a mammal, a mammal is different from a fish, and a fish is different from a bird. l Even though they are all different from each other, they are the same in regard that they are all animals .
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Computer Programming II 6 6 Example 2/2 l Under the Human class, we can create two subclasses: Lecturer and Student . l Sharaf is an instance of Lecturer. Tom is an instance of Student. l Sharaf and Tom are also humans
Background image of page 6
Computer Programming II 7 7 The "is-a" Relationship l The common relationship between these classes is what can be referred to as the " is-a " relationship. l The objects of a subclass are also members of the more general class (called superclass ) l Recall that objects that are grouped together into a class have a common set of attributes and behaviors(methods) Thus, all objects of Animal have a common set of attributes and behaviors, and all objects of Bird have a common set of attributes and behaviors Sharaf "is-a" human. Tom "is-a" human. Shark "is-an" Animal. Parrot "is-an" animal. A lecturer "is-a" human. A student "is-a" human.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/03/2012 for the course IT 1241 taught by Professor Pang during the Spring '11 term at Multimedia University, Cyberjaya.

Page1 / 28

Lecture08-Inheritanc - Inheritance Part I 1 Computer Programming II Learninig Objectives l l l l l l l To understand the"is-a relationship To

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online