Java Foundation---No parameter no return value method used in Java (36)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.