O'Reilly logo

Sun Certification Training Guide (310-025, 310-027): Java™ 2 Programmer and Developer Exams by Jamie Jaworski

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Declaring and Using Methods

Methods are declared using the following syntax:

modifiers returnValue methodName(parameterList) throwsClause
{
 // Method body
}

A method can have any access modifier (public, protected, private, or package access) or the special modifiers (abstract, final, native, static, or synchronized). The use of these modifiers is covered later in this chapter.

The return type of a method can be any of the following:

  • void. The method does not return a value.

  • A primitive type. The primitive types boolean, byte, char, short, int, long, float, and double can be used as a method return type. The method must return a value that is promotable (refer to Chapter 3, “Operators and Assignments”) to the specified return type.

  • Object ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required