Home > Java > javaTutorial > body text

What is the return value in Java

little bottle
Release: 2019-05-30 17:45:20
Original
14945 people have browsed it

What is the return value in Java

In the case of ordinary classes or when you define a java method, you must define a return value type or use a void placeholder.

Then return a return value at the end of the method body, which needs to be consistent with the return value type when defined. Then when this method is called, the return value will be transferred to the calling location.

To put it simply, the return value is to return a signal or result to you after doing something.

/**
 *    方法
 */
public static String add(){//String返回值类型的方法
    String num;//定义一个String局部变量
    return num;//返回局部变量
}
 
/**
 *    主函数
 */
public static void main(String[] args){
    add();//调用add方法
}
Copy after login

The above is the detailed content of What is the return value in Java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template