{[ 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 ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern