Object-Oriented Knowledge Points in Chapter 2

1. Define a method with parameters

    <access modifier> return value type <method name> (<parameter list>) {

        // body of the method

    }

    (1) <Access modifier> Only the scope of permissions that the method is allowed to be accessed, which can only be public, protected or private. The public access modifier means that the method can be called by any other code.

    (2) The return value type refers to the type of the return value of the method. If the method does not return any value, it should be declared as void. Java is very strict about the return value, and the method return value must match the stated type. Use the return statement to return a value.

  (3) <method name> is the name of the defined method, which must use a legal identifier.

  (4) <parameter list> is the parameter list passed to the method. The parameters in the list are separated by commas. The format of the parameter list is as follows.

            grammar:

                data type parameter 1, data type parameter 2, ...., data type parameter n


  This chapter concludes:

    1. The method of defining a class must include the following three parts.

        * The name of the method.

        * The type of the return value of the method.

        * The body of the method.

    2. Class method calls, use the following two forms.

        * A method in the same class, call the method directly using the method name.

        * For methods of different classes, first create an object, and then use "object name.method name" to call.

    3. In java, there are member variables and local variables, and their scopes are different.

    4. The javaDoc comments start with "/**" and end with "*/", and provide JavaDoc comment tags. Development documentation can be generated using javaDoc technology.

    5. The syntax of calling a method with parameters is the same as calling a method without parameters. When calling a method with parameters, the actual parameter value must be passed in.

    6. The formal parameter is the name of the parameter when the method is defined, and the actual parameter is the actual value passed to the method when the method is called.

    7. Java provides packages to manage classes. Use the keyword package to declare a package, and use the keyword import to import a package.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325911205&siteId=291194637