Object Oriented Programming in Java: Data Structure

Course notes toward Data Structure by University of California, San Diego

Course 4 - Data Visualization

Week 4

Inheritance Constructors - hierarchy.

Overloading - Same class has same method name with different parameters.

Overriding - Subclass has same method name with the same parameters as the superclass.

Person s = new Student("Cara", 1234);

Student, Faculty extends Person class.

  1. Compile Time Rules - only knows reference type
  2. Runtime Rules - follow exact runtime type of object
  • Automatic type promotion (like int to double)
    • Superclass superRef = new Subclass();
  • Explicit casting (like double to int)
    • Subclass ref = (Subclass) superRef;

Runtime type check - instanceof


Abstract Classes and Interfaces

public abstract class Person{}

public abstract void monthlyStatement(){}

Abstract classes offer inheritance of both

  • Implementation
  • Interface - only define required methods & inherit from multiple interfaces