1. Two main characteristics of an object: properties and methods.
2. Method: The Access modifier method returns a value type method name () {
The body of the method
}
3. No parameter method:
(1) There is a return value
For example: Public String play () {
The type of the return value is consistent with the return value type of the method
return "hehe";
}
(2) No return value
For example: public void play () {
}
4. With the parameter method: Mutual invocation is allowed between methods.
5. member variables and local variables:
(1) A member variable refers to a variable in a class
Can be used anywhere in the class! Java gives the member variable an initial value.
(2) A local variable refers to a variable in a method
Can only be used inside the method, out of the way is not in! Java does not assign an initial value to a local variable.
In the same class, a local variable has a higher precedence when the member variable has the same name as a local variable.
3.JavaDoc
Start with "/**" and End With "*\".
Electric Lion Category:
Public classautolion{String Color= "Yellow"; Color
/* Run * / Public voidrun () {System.out.println ("Running forward at 0.1 m/s.");}
/* Snatch Ball */publlic string Robball () {string ball= "Ball"; returnBall;}
/* Get color * / PublicString GetColor () {returncolor;}
/* Show Lion's features * / PublicString showlion () {return"This is a" +getcolor () + "Toy Lion!";}
Test class:
publicclass testlion{ publicstaticvoid main (string[] args); =new autolion (); Create Autolion object String Info=lion.showlion (); Call the method and receive the return value of the method System.out.println (info); Display class Information lion.run (); Call the way to run System.out.println ("Grab a" + Lion.robball ();)//Call the ball method
Non-parametric method of class