Object-Oriented Programming with Java Lecture Notes

21 February 2008 • Polymorphism


Outline

Protocol Classes

Abstract Methods

Abstract-Method Example

Another Protocol-Class Property

Abstract Class

Abstract-Class Methods

Abstract Classes and Inheritance

Abstract-Class Types

Abstract Type Example

The Object Class

Object Polymorphism

Casting

Object-Casting Problems

Generics

Object Methods

Equality

Identity vs. Simularity

Object.equals()

Equality Contract

Contract Rules

Equality Example

public boolean
equals(Object o)
  if this == o     // reflexive
    return true

  if o == null     // null rejecting
    return false;

  if getClass() != o.getClass()
    return false

  final Card c = (Card) o
  
  return 
    c.suit == suit && 
    c.rank == rank

Equality vs. Inheritance

Object.hashCode()

hashCode() Example

Object.toString()

Summary


This page last modified on 22 February 2008.

This work's CC license.