Use of no parameter-return-value method in Java

Source: Internet
Author: User

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

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.