Mu class net-java first season -7-2 the use of no parameter and no return value method in Java

Source: Internet
Author: User

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

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.