lec21 - Lecture 21 Class Hierarchies (Savitch 7.1)...

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

View Full Document Right Arrow Icon
Lecture 21 • Class Hierarchies (Savitch 7.1)
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS125 Course Notes Lecture 21, Slide 2 Hierarchies • Information may be organized in a non- linear manner. • Hierarchies represent dependencies or relationships in a non-linear, tree-like structure. • Examples: – Animal kingdom – Classification of matter
Background image of page 2
CS125 Course Notes Lecture 21, Slide 3 Example Animal Mammal Bird Fish Cat Dog Cow
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS125 Course Notes Lecture 21, Slide 4 Another example Matter Pure substances Mixtures Heterogeneous Homogeneous Compounds Elements
Background image of page 4
CS125 Course Notes Lecture 21, Slide 5 Observations • Notice that the root of the hierarchy is the most general (Animal, matter) • As we move down through the tree, we become more specific – The attributes become increasingly well- defined. – Example: Cat is more specific than Mammal is more specific than Animal.
Background image of page 5

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

View Full DocumentRight Arrow Icon
CS125 Course Notes Lecture 21, Slide 6 Observations continued • Attributes are passed down the tree – Example: if mammals have fur, then a cat will have fur. • The CS/Java/OO hierarchies will guarantee the above point – In “real life”, not all attributes are inherited
Background image of page 6
CS125 Course Notes Lecture 21, Slide 7 How does this relate to CS? • We will treat these classes of things as objects , and relate them together using INHERITANCE
Background image of page 7

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

View Full DocumentRight Arrow Icon
CS125 Course Notes Lecture 21, Slide 8 Animal • Suppose we know that all animals have a name. • We can do the following to the name: – Set – Compare – Retrieve
Background image of page 8
CS125 Course Notes Lecture 21, Slide 9 The Animal class public class Animal { private String name; public Animal() { name = "Unspecified."; } public Animal(String newName)
Background image of page 9

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

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

Page1 / 23

lec21 - Lecture 21 Class Hierarchies (Savitch 7.1)...

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

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