Java-Preliminary Understanding-fourth-functions-definitions

Source: Internet
Author: User

I. Overview

Another component of the Java Foundation-the function, which is the other language, is a different form of expression. Usage and when to use the same, this is a common concept.

Two. Definition of functions

A function is a small, independent program defined in a class that has a specific function .

"In class" Needless to say, Java is composed of classes, certainly in the class, the most important is "specific features" and "independent".

Functions are also called methods.

What is function? The thing that can be done is function, what can do, what function. For example, explain why there is a concept of function (why it is a scientific problem, in the process of learning, not only to know how to do, but also to know why, why is more important than how to do. ) computes an addition, 3+5, or several additions, 5+6,3+6. If you want to use the addition function in large numbers, and the value is larger, then the direct use of the operator, the operation is not appropriate, we need to separate the addition function, and then use the addition function again, there is no need to do the + operator this operation action.

The essence is to pull out a single operation that will be reused, to be a separate thing. This thing has a specific function, which we call a function (called a function)

Three. Format of functions

Because the function is drawn out, independent, abstract, with a specific function of things, in the writing of the corresponding format.

How to use the defined function.

Here are a few things to note: The modifier for the main function, static modifier for main, which must also be static when calling something else. The public modifier represents the permission.

In the addition function, we write the operation directly in the code block, we do not need to control how this function is implemented, the specific implementation is determined by the bottom, we just know that in a fixed format to write, we can have such a function.

Then I operated on my own and the results were as follows:

Note: The thought is not concentrated, in the main function we want to use the addition function, to give the specific value. After giving the specific values, the DOS display is as follows:

We try to put the defined addition function into the main function, and the result is still an error.

A closer look reveals that the addition function is independent of the main function, but we add a semicolon to the definition.

The reason for the repeated error is that the modified saved source program is not in the 20 folder, and the 20 folder is always an incorrect file. As shown below:

Java-Preliminary Understanding-fourth-functions-definitions

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: 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.