Java Annotations:
: Single-line comment
/**/: Multiline Comment
/** */:javadoc Notes
Method:
Grammar:
Access modifier return value type method name () {
Method body
}
Example:
public void Run () {
System.out.println ("");
}
Public String Robball () {
String ball= "Ball";
return ball;
}
The return value of the method:
1. If the method has a return value, the method must return the value using the keyword return, the type of the return value type
return expression, function: Jump out of method, return result
2. If the method does not return a value, the return value type is void
Case:
public class Lion {
Color Properties
String color;
int age;
public void Run () {
System.out.println ("Lion is Running");
}
public void Say () {
System.out.println ("The lion is hungry and calls to eat");
}
Public String Robball () {
System.out.println ("hehe");
String ball= "Volleyball";
return ball;
}
Getting the lion's age
public int getage () {
int age=18;
return age;
}
}
public class Test {
public static void Main (string[] args) {
Lion lion = new lion ();
/*lion.run ();
String ball = Lion.robball ();
System.out.println ("Lion is playing:" + ball);
System.out.println ("Come back after the method has been executed!") ");
*/
System.out.println (Lion.getage ());
}
}
Local variables and member variables:
Different scopes
The scope of a local variable is limited to the method that defines it
The scope of a member variable is visible within the entire class
Different initial values
Java will give the member variable an initial value
Java does not give initial values to local variables
Attention:
Local variables with the same name are not allowed in the same method
In different methods, you can have local variables of the same name
Local variables have higher precedence in the same class when the member variable and local variable have the same name
Non-parametric methods for Java classes