‹header›
‹date/time›
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
‹footer›
‹#›
Repeat slide from last lecture. No need to spend time on it.
Repeat slide from last lecture. No need to spend time on it. Students who didn’t get copies of OverridingDemo.java can pick them up now, but don’t spend time rereading the code.
Repeat slide from last lecture, but didn’t get to discuss it. Point out in OverridingDemo.java which line of code produces this output – the one with “super” that invokes overridden toString from Object.
For those who know about pointers, the hex number is a kind of memory address (internal to Java, not a real memory address).
Repeat slide from last lecture. Not discussed last time, so worth a minute or two now. This is literally pasted from the Java sources – most of Java is in the library, and written in Java itself.
Repeat slide from last lecture. Not discussed then. If you use this elegant construction you’re speaking Java like a native rather than a newcomer. Whether or not you use it in the code you write, you need to be able to read it since other people use it in programs you read.
Repeat slide from last lecture. Discussed then. Don’t spend time on it now unless there are questions.
Hand out code for Bank.java.
New keywords in red.
Text is pasted from Bank.java, but variable and class names have been abbreviated to fit on slide.
Not handing out SwitchDemo.java code.
Next to last bullet: switch syntax is a relic from C. Here’s what I think it should have been:
case (whatever) {
// body
}
Important points here:
another use for break
my change to the API in order to accommodate both “cash check” and “close” as commands. Sutdents don’t have the right to change the API, but I do. Note that I consistently require the whole word to end something – “exit”, “quit”, “close”.
Not handing out the code for the demo program.
Whether or not using these early returns is a good idea is an “it depends” question. The two bullets summarize the pros and cons.
Early loop exits were explicitly forbidden in Pascal. Early loop exits make mathematical analyses of programs harder.
This is easy code to read – use the Java 1.5 as pseudocode. Lines 203ff in Bank.java use Java 1.4 iterator.
This is the most important new concept for this lecture. We return to it several times. Review the previous slide after looking at this one, point out how the Bank doesn’t care what each individual account does when it gets the newMonth message.
This is another example of polymorphism – a little more subtle since the withdraw method is actually in the parent BankAccount class, unlike the abstract newMonth method. The polymorphism comes in when withdraw sends the countTransaction method, which some child classes override. The Bank doesn’t know or care.
First use of || in the course.
Last bullet repeats a point from an earlier slide about changing the API.
This slide is a repeat from several weeks ago. Do it again.
Following slides don’t have notes yet.