Source: http://www.imooc.com/code/1578
If the method does not contain a parameter, and there is no return value, we call it a method without parameters and no return value.
The use of the method is in two steps:
The first step is to define the method
For example, the following code defines a method named show with no parameters and no return value, and the operation is output "Welcome to IMOOC."
Attention, OH:
1, the method body is placed in a pair of curly braces, to achieve a specific operation
2, the method name is mainly used in calling this method, you need to pay attention to the naming of the specification, generally use the first letter lowercase, other words capitalized form
The second step is to invoke the method
When you need to invoke a method to perform an action, you can first create the object of the class, and then implement it (the concept of classes and objects will be explained in detail in the following chapters, first familiar with the grammar, the table anxious Oh ~ ~)
For example: In the following code, we create an object named Hello, and then output the information by calling the show () method of the object
Operation Result:
Task
Check the work again!!!
In the editor, a method named Showmylove with no parameter return value is defined to output the information. Please complete the code in section 5, 8, and line
The result of the operation is:
1 Public classHelloWorld {2 3 Public Static voidMain (string[] args) {4 //Create object, object named Hello5 6 7 //Calling Methods8 9 }Ten One /* A * Method for defining no return value without parameters - */ - PublicShowmylove () { theSystem.out.println ("I adore the net!")); - } -}
Myans:
1 Public classHelloWorld {2 3 Public Static voidMain (string[] args) {4 //Create object, object named Hello5HelloWorld hello=NewHelloWorld ();6 7 //Calling Methods8 Hello.showmylove ();9 }Ten One /* A * Method for defining no return value without parameters - */ - Public voidShowmylove () { theSystem.out.println ("I adore the net!")); - } -}
Mu class net-java first season -7-2 the use of no parameter and no return value method in Java