Introduction to Interactive Programming
by Lynn Andrea Stein
A Rethinking CS101 Project

Java Charts

Class Declaration 7

public

Optional: 0 or 1.

If public, a class name is universally visible for use as a type. Otherwise, the class name is only visible within this package.

Note that the file in which a public class ClassName is defined must have the name ClassName.java

final

Optional: 0 or 1.

If final, no subclasses of this class can be defined, i.e., no other class can extend this one.

abstract

Optional: 0 or 1.

If abstract, no instances of this class can be created, i.e., new ClassName(...) is a (compile-time) error.

class ClassName

Exactly 1.

This name is a Java type that can be used anywhere it is visible. If the class is defined in a package other than the default, its proper name is packageName.ClassName, though this may be abbreviated using import statements.

extends OtherClassName

Optional: 0 or 1.

If present, this class "inherits" implementation from OtherClassName. Specifically, all non-private fields and methods defined for OtherClassName are available to/through class ClassName and its instances,3 unless they are explicitly overridden.

In this case, ClassName is said to be a subclass or child of OtherClassName; OtherClassName is a superclass or parent of ClassName.

implements InterfaceNameList

Optional: 0 or 1 implements, followed by 1 or more comma-separated InterfaceNames.

If this declaration is present, ClassName must provide implementations of each of the methods declared for each InterfaceName.

{ body }

Exactly 1, but body may be empty.

If not empty, body consists of members -- field, method , constructor, and inner class declarations, but no freestanding code. 2


© 1999 Lynn Andrea Stein

This chapter is excerpted from a draft ofIntroduction to Interactive Programming In Java, a forthcoming textbook from Morgan Kaufmann Publishers, Inc. It is a part of the course materials developed as a part of Lynn Andrea Stein's Rethinking CS101 project at the MIT AI Lab and the Department of Electrical Engineering and Computer Science at the Massachusetts Institute of Technology.

Questions or comments:
<[email protected]>

Last modified: Thu Jul 10 13:01:20 1997