Introduction to Inheritance

Interfaces Inheritance
An interface provides an abstract, "umbrella" type that brings together one or more classes. (The classes implement the interface.)
  • type is defined as a set of operations
  • provides descriptions/specifications for methods
  • no implementation for those methods!
  • no state
  • cannot instantiate
  • useless unless there are classes that implement them
Implementing Interfaces: To implement an interface, a Java class must:
  • say it plans to implement the interface
  • implement all the methods specified in the interface
A class can act as an abstract, "umbrella" type that brings together one or more subclasses. (The subclasses extend the superclass.)
  • superclass may have state and methods (it's a class, after all)
  • subclass inherits the superclass's state
  • subclass inherits the superclass methods
  • subclass may include additional instance variables and methods
  • subclass may redefine/override some methods
Extending Superclasses: To extend a class, a subclass must:
  • say it plans to extend the superclass
  • add or override any necessary state/methods

Polymorphism and Dynamic Binding:
  • works the same for interfaces and inheritance

Alyce Brady, Kalamazoo College