Lecture 6: Interfaces, Polymorphism, Inheritance

What You Will Learn Today

  1. Compare programming paradigms.
  2. Create and use interfaces.
  3. Use polymorphism.
  4. Use inheritance to create and use subclasses.
  5. Use method overloading and overriding.
  6. Use abstract classes and methods, final classes and methods, and nested and inner classes.

Programming Paradigms

Approaches to programming have developed over time roughly in this order:

  1. monolithic program: one long main method, global variables, unstructured branching
  2. procedural program: procedures with parameters and return value; local variables
  3. modular program: set of procedures with data they manipulate; data is hidden in the module
  4. abstract data types: user-defined types used in addition to built-in types
  5. object-based program: classes of objects which group methods and attributes
  6. object-oriented program: objects belong to a hierarchy of classes which share properties through inheritance
  7. generic program: a group of algorithms that work for a variety of data structures

Why are these new approaches necessary?

Interfaces

public interface InterfaceName
{
   returnType methodName(parameters);
}

public interface Measurable
{
   double getMeasure();
}

public class ClassName implements InterfaceName1, InterfaceName2, ...
{
   accessType returnType methodName(parameters) { implementation } ...
}

public class BankAccount implements Measurable
{
   public double getMeasure() { return balance; }
}

Using Interfaces

Polymorphism

Inheritance

Inheritance Hierarchy

Using Inheritance

Overriding Methods

Abstract Classes and Methods

Final Classes and Methods

Nested and Inner Classes

To Do After Class