lecture9-jun24 - 1 Lecture 9 Announcements • Read Book Ch...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: 6/24/09 1 Lecture 9 Announcements • Read Book Ch. 3.1-3.4, skip Ch. 2 for now • Assignment 2 – out today – Q&A due Friday – designs due Monday • Use case diagram, UML class diagram, functional block diagram, main algorithm, ADT descriptions for both subclasses – Program due next Friday • Today – Inheritance – File IO Objects and Relationships • Object oriented programming leads to programs that are models – sometimes models of things in the real world – sometimes models of contrived or imaginary things • There are many types of relationships between the things in the models, e.g. in a Chess Game – A chess piece has a position – A chess piece has a color – A chess piece moves (changes position) – A chess piece is taken – A rook is a type of chess piece Chess Board Chess Pieces Inheritance and Class Hierarchies • Inheritance in OOP is analogous to inheritance in humans • Inheritance and hierarchical organization allow you to capture the idea that one thing may be a refinement or extension of another • Popularity of OOP is that it enables programmers to reuse previously written code saved as classes • All Java classes are arranged in a hierarchy, starting with Object, which is the superclass of all Java classes Is-a and Has-a Relationships • One misuse of inheritance is confusing the has-a relationship with the is-a relationship • is-a means that one class is a subclass of the other – The keyword extends specifies this in Java • The has-a relationship means that one class has the second class as an attribute (is composed of) – This is implemented with a data field of the second type • We can combine is-a and has-a relationships public class JetAirplane extends Airplane { private JetEngines [ ] engines; //… } Inheritance Hierarchy Throwable BankAccount Driver Chapter 2 Preview 6/24/09 2 Inheritance • Inheritance allows one object to acquire the properties of another object (from its ancestor) • Its purpose is to allow us to build hierarchical classification schemes,e.g. – A red delicious apple is-a apple is-a fruit is-a food • Makes it possible for an object to be a specific instance of a more general case • A general class defines common traits, and a more specific subclass only adds those things that are unique to the subclass (or subtype) Nomenclature of Inheritance • In Java the extends keyword is used to specify which pre-existing class a new class is inheriting from public class Student extends Person • Person is said to be – the parent class of Student – the super class of Student – the base class of Student – an ancestor of Student • Student is said to be – a child class of Person – a sub class of Person – a derived class of Person – a descendant of Person Person Student IS-A Inheritance Among Classes superclass subclass B Is a type of A “extends” • A and B are classes that are related by inheritance • What does the class B inherit from A?...
View Full Document

This note was uploaded on 09/15/2009 for the course EE 322C taught by Professor Nettles during the Summer '08 term at University of Texas.

Page1 / 6

lecture9-jun24 - 1 Lecture 9 Announcements • Read Book Ch...

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

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