Method parameters and return values in JAVA classes

Source: Internet
Author: User

A method with no parameters and no return value, declared with the public void method name;

A method with no return value, declared with the public void method name;

A method with a parameter that returns a value, declared with the public int method name (int i,int n), (int is the data type of the parameter or other data type, for example: String, char, double, int).

Instance:

//Defining Classes Public classtest{//method of no parameter return value     Public voideat () {System.out.println ("I was eating." "); }    //methods with no return value for parameters     Public voidChengintIintN) {System.out.println (i*N); }    //methods of having a parameter return value     Public intGetage (inta) {        returnA; }     Public Static voidMain (string[] args) {Test Myclass=NewTest ();//Creating ObjectsMyclass.eat ();//Calling MethodsMyclass.cheng (9,9);//Calling MethodsSystem.out.println (Myclass.getage (18));//Calling Methods    }}

Method parameters and return values in JAVA classes

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.