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.
First Definition method
Defines a method named show with no parameters and no return value, and the operation is output "Welcome to IMOOC"
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 pass the object name. Method Name (); To achieve
PackageCn.zhaoqiang.homework1; Public classHelloWorld {//Defining Methods Public voidShow () {System.out.println ("Welcome to IMOOC"); } Public Static voidMain (string[] args) {//Create object, object named PPHelloWorld pp =NewHelloWorld (); //The method is called through the object name. Method Name (). pp.show (); }}
Operation result is;
Use of no parameter-return-value method in Java