Lecture 9 of 12
Computer Science A, Spring 2007
Previous
Next
Overview
Lecture 9: Classes and Inheritance
Reading material:
Chapter
9
Section 9.1-4
Section
9.6-8
Chapter
11
Section 11.1-3
Chapter
13
Section 13.1-6
Section
13.7-8
Exercises:
Review Exercise 9.1
Review Exercise 9.24
Programming Exercise 9.1
Programming Exercise 9.2
Programming Exercise 9.10
Review Exercise 11.1-3
Programming Exercise 11.1-2
By "the first implementation of the
DataSet
class" the author refers to the implementation on page 412.
Programming Exercise 11.4
Programming Exercise 11.9
Ignore the warning that the compiler displays when you compile your new
DataSet
class.
Programming Exercise 11.10
Programming Exercise 11.17
This exercise is fairly challenging.
Review Exercise 13.1-7
Programming Exercise 13.1-4
Programming Exercise 13.6
Slides:
1
Chapter 9: Designing classes
30
An Introduction to Inheritance
2
Choosing Classes
31
Layout of a Subclass Object
3
Choosing Classes
32
Inheritance Hierarchies
4
Cohesion
33
A Simpler Example: Hierarchy of Bank Accounts
5
Cohesion
34
Inheriting Methods
6
Coupling
35
Inheriting Instance Fields
7
Coupling
36
Implementing the CheckingAccount Class
8
High and Low Coupling between Classes
37
Inherited Fields are Private
9
Static Methods
38
Invoking a Superclass Method
10
Self Check
39
Syntax 13.2: Calling a Superclass Method
11
Answers
40
Implementing Remaining Methods
12
Static Fields
41
Subclass Construction
13
Static Fields
42
Syntax 13.3: Calling a Superclass Constructor
14
Chapter 11: Interfaces and Polymorphism
43
Converting Between Subclass and Superclass Types
15
Using Interfaces for Code Reuse
44
Converting Between Subclass and Superclass Types
16
Using Interfaces for Code Reuse
45
Converting Between Subclass and Superclass Types
17
Using Interfaces for Code Reuse
46
Syntax 13.4: The instanceof Operator
18
Interfaces vs. Classes
47
Polymorphism
19
Generic DataSet for Measurable Objects
48
Polymorphism
20
Implementing an Interface Type
49
File AccountTester.java
21
Converting Between Class and Interface Types
50
File BankAccount.java
22
Casts
51
File CheckingAccount.java
23
Self Check
52
File SavingsAccount.java
24
Answers
53
Output
25
Polymorphism
54
Self Check
26
Polymorphism
55
Answers
27
Chapter 13: Inheritance
56
Object: The Cosmic Superclass
28
An Introduction to Inheritance
57
Overriding the toString Method
29
An Inheritance Diagram
58
Overriding the toString Method
You can find a
printer-friendly overview here
.