Use of no parameter-return-value method in Java
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."
650) this.width=650; "style=" width:340px; src= "Http://img.mukewang.com/537d655b0001a44305790111.jpg"/>
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 an object of the class and then this.width=650 through 650); "src=" http://img.mukewang.com/537d65950001b7b901340024.jpg "/ > to implement (the concept of classes and objects will be explained in detail in the following chapters, first familiar with grammar, 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
650) this.width=650; "style=" width:340px; src= "Http://img.mukewang.com/537d65be0001aecb06640362.jpg"/>
Operation Result: 650) this.width=650; "src=" http://img.mukewang.com/537d6a3a0001515801900025.jpg "/>
Code:
public class HelloWorld {
public static void Main (string[] args) {
Create object, object named Hello
HelloWorld hello=new HelloWorld ();
Calling methods
Hello.showmylove ();
}
/*
* Method for defining no return value without parameters
*/
public void Showmylove () {
System.out.println ("I adore class net!");
}
}
Running result: I adore the net!
This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1547996
Java Foundation---No parameter no return value method used in Java (36)