02 ObjectsAndClasses
02 ObjectsAndClasses
Object-Oriented Programming
Outline
Readings:
■ IPIJ: Ch.3.
Introduction to Java 2
Abstract data types
6
Using color: monochrome luminance
7
Computing with color: grayscale
8
Picture ADT
9
Picture client example: Grayscale filter
10
Picture client example: Grayscale filter
11
OOP Concept: Abstraction
12
OOP Concept: Abstraction
13
Classes
■ Classes
❑ are the templates to create objects (instantiate).
make up programs.
❑ Objects are what are created (from a class) at run-time
OOP Concepts 14
Objects
■ Object Identities
❑ Java object ids, probably the address of the object
■ Object State 🡪 Attributes / Instant variables
❑ (20lit, 0km/h,”143 WJT”)
❑ accelerate()...
OOP Concepts 15
class Car {
OOP Concepts 16
Inheritance
Mom’s eyes
Dad’s smile
Mom’s love
Dad’s sports
of ROCK
obsession
OOP Concepts 17
Inheritance
■ “is-a” relations
■ The general classes can be
specialized to
more specific classes
■ Reuse of interfaces & implementation
■ Mechanism to allow derived classes to possess attributes
and operations of base class, as if they were defined at
the derived class
■ We can design generic services before specialising them
OOP Concepts 18
Polymophism Jump!
Polymorphism:
❑ "more than one form"
Object polymorphism:
■ Different types of objects can respond to the same message
OOP Concepts 19