CS 424 Java - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

CS 424 Java

Description:

The illiterate of the 21st century will not be those who cannot read ... Alvin Toffler. Today's Agenda. Chapter 9: Object-Oriented Programming. Sections 9.1-9.9 ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 20
Provided by: Marcus3
Category:
Tags: alvin | java

less

Transcript and Presenter's Notes

Title: CS 424 Java


1
CS 424 Java
  • Class 14
  • Tuesday, February 22, 2000

2
Thought for the Day
  • The illiterate of the 21st century will not be
    those who cannot read and write, but those who
    cannot learn, unlearn, and relearn.
  • Alvin Toffler

3
Todays Agenda
  • Chapter 9 Object-Oriented Programming
  • Sections 9.1-9.9
  • Hope to return exam Thursday
  • Next project assignment Thursday

4
Reading Assignment
  • Today Finish chapter 9.
  • Thursday Chapter 10 Strings Characters

5
Seminar Today
  • Electronic Commerce The End of the Beginning?
  • Nenad Jukic, PhD from UA
  • Now at Loyola University
  • 5PM today, EE 119

6
ACM Meeting
  • Bret McKee, Exxon-Mobil
  • What you (dont) need to know in the real
    world!
  • Thursday, 5PM, EE 119

7
Reading Quiz
  • Assume BaseClass is extended by Class1 which
    is extended by Class2
  • Assume objects bC, c1 and c2 of those
    classes. Which of the following can you do?
    What happens if you cant?
  • c1 bC
  • bC c1
  • c2 bC
  • c1 c2

8
Quiz Answers
  • Background you need
  • BaseClass is the superclass to Class1, which
    is the superclass to Class2
  • bC, c1 and c2 are references, not objects!
  • You can make a superclass reference point to a
    subclass object, but you cant make a subclass
    reference point to a superclass object!

9
Quiz Answers (2)
  • Assuming that each reference points to an object
    of its own type
  • c1 bC Cant gets a ClassCastException
  • bC c1 Can
  • c2 bC Cant same exception
  • c1 c2 Can

10
Chapter 9 Object Oriented Programming
  • Superclass and subclass
  • Polymorphism
  • Abstract methods, abstract classes
  • Overriding methods
  • Dynamic binding
  • Interfaces

11
Polymorphism
  • Makes programs more extensible.
  • If several classes inherit from one superclass,
    they can all use the same method.
  • Example Window methods
  • Open, close, move, repaint,
  • All sub-Window objects could inherit, probably
    override them.

12
Polymorphism (2)
  • Same command ?
  • different objects ?
  • many forms (polymorph)
  • myWindow.open()
  • If myWindow is a text window, or a graphics
    window, or What would be different?

13
Abstract classes
  • Similar to Cs abstract base class
  • Javas abstract methods similar to Cs pure
    virtual functions
  • Meant to be overridden in subclasses
  • You cant create an object of an abstract class,
  • But you can create a reference to an abstract
    class!
  • Try it! Whats the difference?

14
Overriding methods
  • In the subclass, write a new version of the
    method.
  • You can call the super.method() if you wish.

15
Dynamic binding
  • Which method gets called for an object?
  • If the reference to the object is a superclass
    reference, it could be the superclass method, or
    the subclass method.
  • If the hierarchy is deep, several options
  • Binding is at execution time.

16
Example Code
  • Figure 9.9

17
Interfaces
  • Can use an interface instead of a superclass.
  • Subclass must implement all the methods in the
    interface.
  • Old example chapter 6
  • Implemented ActionListener
  • Wrote actionPerformed
  • Use interface when there are no instance
    variables and no default method implementations.

18
Example Code
  • Figure 9.11

19
Exercise
  • Page 452, 9.25
Write a Comment
User Comments (0)
About PowerShow.com