Concept:
Two main characteristics of an object:
Properties and Methods
1. Method:
The access modifier method returns a value type method name () {
The body of the method
}
1. No parameter method
has a return value
For example: Public String play () {
Return value type is consistent with the returned value type of the method
return "hehe";
}
No return value
For example: public void play () {
}
2. With the Parameter method
Allows mutual invocation between methods
2. member variables and local variables
A member variable refers to a variable in a class//can be used anywhere in a class! Java will give the member variable an initial value
Local variable refers to the variable in the method//can only be used inside the method, out of the way is not in! Java does not give initial values to local variables
Example 1
public class autolion{
String color = "yellow";//Run method
public void Run () {
SYSTEM.OUT.PRINTLN ("Running forward at 0.1 m/s)";} Call method
public void Cry () {
System.out.println ("Shout loudly!" ");}//method
Public String Robball () {
String ball= "Ball";
return ball;
Non-parametric method of class