public protected private |
Optional: 0 or 1.
If public, the method is visible and callable everywhere, and
inherited by all subclasses. Otherwise, it is visible, callable, and inheritable only within the package. |
static | Optional: 0 or 1.
If static, the method belongs to the class (factory, recipe) and not to its instances. In this case, it is referenced as ClassName.methodName rather than through its instances. |
abstract
final |
Optional: 0 or 1.
If abstract, the method body is replaced by a semicolon (;) and the class is alsoabstract, i.e., it cannot be instantiated (used with new). The method body is typically defined in a non-abstract (instantiable) subclass. If final, the method must not be abstract and may not be overridden (shadowed) in subclasses. |
synchronized | Optional: 0 or 1.
If synchronized, method cannot begin to execute an exclusive lock has been obtained on the containing object (i.e., the instance denoted by this, for non-static methods, or the class, for c methods). |
native | Optional: 0 or 1.
If native, the method is defined in a language other than Java and hence outside the scope of this course. |
ReturnTypeName | Exactly 1.
May be a class or interface name, one of the eight Java primitive types, an array type, or the special keyword void |
methodName | Exactly 1. |
( ArgType argName, ... ArgType argName ) | Exactly 1, but argument list may be empty.
Each ArgType may be a class or interface name, one of the eight Java primitive types, or an array type. When the method is invoked, arguments of appropriate types must be supplied. If there is more than one ArgType argName pair, the pairs are separated by commas. Parentheses must be present even if the argument list is empty. |
throws ExceptionNameList | Optional: 0 or 1 throws, followed by 1 or more comma-separated
ExceptionNames.
This declaration must be present if methodName or any method called by it might throw an uncaught exception of type ExceptionName5 |
{ body }
; |
Exactly 1, but body may be empty.
Body may contain one or more statement. If braces and body are absent, aemicolon is used insead and method is abstract. |
© 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:Last modified: Thu Jul 10 13:01:20 1997
<[email protected]>