Skip to content

Latest commit

 

History

History
40 lines (27 loc) · 1.22 KB

File metadata and controls

40 lines (27 loc) · 1.22 KB
layout page
title 401.06 Reading Notes
permalink /401-R06/

Inheritance & Interfaces

Inheritance

  • In Java, subclasses of a class ("superclass" relative to the subclass) inherit state and behavior, such as having access to all methods defined for the parent class.

  • Each class may have only one superclass "above" it in inheritance, but has no limit to the number of subclasses "below".

  • Subclass delcaration syntax: class SubclassName extends SuperclassName {/*subclass code block*/}

Interfaces

  • In Java, an interface is a specified list of object behaviors.

  • Interface syntax: interface ClassName { void methodToImplementLater(int parameterName); }

  • An implemented class must define each method declared in the interface.

  • Implementation syntax: class ImplementedClassName implements ClassName { /*code block*/ void methodToImplementLater (int parameterName) { /*method code block*/ }

Packages

  • A Java package is a grouping of related or otherwise interacting classes and interfaces.

  • The Application Programming Interface package for Java contains very many commonly used classes (Documentation Here)