Lecture 13 - Classes 2

Lecture 13 - Classes 2 - Relationship Among Classes...

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

View Full Document Right Arrow Icon
Inheritance Classes may be related by inheritance o A subclass(derived class) inherits behaviour (instance methods) and structure (instance variables) from its superclass(base class) o A subclass may also augment or redefine the behaviour and structure inherited from its superclass o Inheritance indicates an “is a kind of” relationship Classes related by inheritance form a class hierarchy o Also called a generalization/specialization hierarchy Inheritance helps create compact code o General functionality is put into superclasses o Specialized functionality is added to the general case by creating the appropriate subclass Often you subclass from existing classes in a library Save you much labour! o The subclass reuses code from the superclass for non-specialized functionality Single Inheritance o Where subclasses can only have one immediate superclass o Mammal / | \ canine feline primate | | | dog wolf fox lion tiger puma chimpanzee
Background image of page 1

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

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

This note was uploaded on 11/04/2010 for the course CPSC 233 taught by Professor Li during the Fall '09 term at University of Calgary.

Page1 / 4

Lecture 13 - Classes 2 - Relationship Among Classes...

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

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