The method of the class must include the following 3 parts.
1, the name of the method.
2. The return value type of the method.
3, the main body of the method.
Grammar:
Public return value type method name () {
The body of the method
}
The method names in Java are generally used in camel-named notation.
Return a value using the return statement
Grammar:
return expression;
Invocation of the method
Grammar:
The name of the object. Method Name ();
The invocation of a method involving a class is used in the following two forms.
1. Methods in the same class, call the method directly using the method name.
2, different classes of methods, first create the object, and then use the "Object name. Method Name" to invoke.
Scope of the variable
public class autolion{
Variable 1 type variable 1;
Variable 2 type variable 2;
Variable 3 type variable 3;
Public Method 1 () {
Variable 4 type variable 4;
}
Public Method 2 () {
Variable 5 type variable 5;
}
}
Variables defined in a class are called member variables of a class, such as variable 1, variable 2, and variable 3. Variables defined in a method are called local variables, such as variable 4 and variable 5.
Member variable: A method of the Autolion class can directly use the member variable defined by the class. If the method of another class is to access him, you must first create the object of the class before you can refer to it by a point operator.
Local variables: Its scope is only within the method that defines the variable, so it can only be used in this method.
In general, there are a few things to consider when using member variables and local variables.
Scopes are different.
The scope of the local Morbihan amount is limited to the method that defines it, which is inaccessible outside the method. The scope of the member variable is visible within the entire class, and all member methods are available, and member variables can be used outside the class if access permission is allowed.
The initial values are different.
For member variables, if you do not give him an initial value in the class definition, Java gives him a default value of 0 for the base data type and a value of NULL for the reference type. However, Java does not assign an initial value to a local variable, so the local variable must be defined and then used.
Attention:
1. In the same method, local variables with the same name are not allowed. In different methods, you can have local variables of the same name.
2. In the same class, the local variable can have the same name as the member variable, and when used, the local variable has a higher precedence.
Attention:
Variables defined in the For loop, while loop, Do-while loop, if selection structure, and switch selection structure are scoped only within these control flow statement blocks.
Javadoc notes
For example:
/**
*accpschool class
* @author Jadebird
* @version 1.0 2011/06/21
*/
Javadoc syntax rules for annotations.
1. Javadoc note begins with "/**" and ends with "*/".
2, each note contains some descriptive text and several Javadoc tags.
3, Javadoc label generally with "@" as the prefix, commonly used Javadoc notes are as follows.
Common Javadoc Tags
Label |
Meaning |
Label |
Meaning |
@author |
Author name |
@version |
Version ID |
@parameter |
Parameters and their significance |
@since |
The first JDK version to use this method/class/interface |
@return |
return value |
@throws |
Exception classes and throwing conditions |
Tip: In MyEclipse, enter "/**" and press ENTER, the MyEclipse platform automatically javadoc the annotation format and the font color is blue. In addition, when using the Javadoc tag, the input @,myeclipse platform automatically explicitly a drop-down list, which provides all the Javadoc annotation tags for the user to select.
How to generate Javadoc documents
There are two main ways to generate Javadoc documents.
1. Generated using the command line method.
2. Generate with MyEclipse tool.
Using MyEclipse to generate a Javadoc document is simple, select the "Export" option from the "File" menu, pop up the "Exports" dialog box, select the "Java" menu Javadoc options, submit.
S1/using Java to understand the program logic/12-class's non-parametric method