View RSS Feed

Java Object

Defining Methods

Rate this Entry
by , 04-26-2012 at 05:13 PM (402 Views)
Typical method declaration is being explained by this example:
Java Code:
public double calculateAnswer(double wingSpan, int numberOfEngines,
                              double length, double grossTons) {
    //do the calculation here
}
Method return name, type, body b/w braces & a parentheses () pair are the required method declaration elements.

There are 6 components of the method declaration, in general.

  1. Modifiers like private, public & many others about which will be discussed later.
  2. The return type is considered to be the data type of that value which has been returned by method or is considered void when a value is not returned by the method.
  3. The method names are field name rules which are being applied to the method names however ther is a bit different convention.
  4. In parenthesis, parameter list is considered as a list which is comma-delimited, of the input parameters, which are then preceded by types of data and finally are closed by the parentheses (). Empty parentheses shall be used when no parameters are there.
  5. An exception list which will be discussed later on.
  6. The method body that is closed b/w the braces, the method's code, the local variables declaration goes here.

Submit "Defining Methods" to Facebook Submit "Defining Methods" to Digg Submit "Defining Methods" to del.icio.us Submit "Defining Methods" to StumbleUpon Submit "Defining Methods" to Google

Categories
Tutorial

Comments