{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# 14 - Hierarchies CS133 Developing Programming Principles...

This preview shows pages 1–6. Sign up to view the full content.

1 CS133: Developing Programming Principles Lecture 14 Class hierarchies, super/subclasses, calling superclass constructors, overriding methods 2 CS133 Course Notes Lecture 14, 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: – People/Students/Co-op students – Classification of matter

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

View Full Document
3 CS133 Course Notes Lecture 14, Slide 3 Example Person Instructor Student Co-op Student Grad Student 4 CS133 Course Notes Lecture 14, Slide 4 Another example Matter Pure substances Mixtures Heterogeneous Homogeneous Compounds Elements
5 CS133 Course Notes Lecture 14, Slide 5 Observations Notice that the root of the hierarchy is the most general (Person, Matter) As we move down through the tree, we become more specific – The attributes become increasingly well- defined. – Example: Co-op Student is more specific than Student, which is more specific than Person. 6 CS133 Course Notes Lecture 14, Slide 6 Observations continued Attributes are passed down the tree – Example: if person has an address, then students will also have an address. The CS/Java/O-O hierarchies will guarantee the above point – In “real life”, not all attributes are inherited

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

View Full Document
7 CS133 Course Notes Lecture 14, Slide 7 How does this relate to CS? We will treat these classes of things as objects , and relate them together using INHERITANCE 8 CS133 Course Notes Lecture 14, Slide 8 Person Suppose we know that all people have a name and an address. We can do the following to the name and address: – Set – Compare – Retrieve
9 CS133 Course Notes Lecture 14, Slide 9 The Person class public class Person { private String name; private String address; public Person(String newName) { this.name = newName; this.address = ""; } public Person(String newName, String newAddress) { this.name = newName; this.address = newAddress; } 10 CS133 Course Notes

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 16

14 - Hierarchies CS133 Developing Programming Principles...

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

View Full Document
Ask a homework question - tutors are online