Java Basics and Javaoo section Summary

Source: Internet
Author: User

The definition format of a function in Java:

Modifier returns a value type function name (parameter type form parameter) {

Execute the statement;

return value;

}

When a function does not have a specific return value, the returned value type is represented by the void keyword.

If a function's return value type is void, the return statement can be omitted, and the system will automatically add it to you.

Return: the End Function. End Function.

Role of the function:

1), for defining functions.

2), used to encapsulate code to improve the reusability of code.

Note: Functions can only be called, and functions cannot be defined.

Main function:

1), to ensure the independent operation of the class.

2), because it is the entrance to the program.

3), because it is called by the JVM.

Overloading is defined as: In a class, if there are two or more than two functions with the same name, as long as they have the number of arguments, or the type of the parameter is different, it can be called the function overload.

array: a container for storing data of the same type. Benefit: You can number the data in the container, starting with 0.

How do you define an array in Java?

1), element type [] Variable name = new element type [number of elements];

2), element type [] Variable name = {element 1, element 2 ...} ;

3), element type [] Variable name = new element type []{element 1, element 2 ...} ;

definition of a two-dimensional array : When the data type in an array becomes an array: int[][] A = new int[row [column];
A two-dimensional array is one that stores an array of an array

Method:

All methods are public static modified before Javaoo

When a method call can get a value of that type (void has no return value

Method Name: Need to be a verb, a noun

Parameter list: Provide the method with the required content

Method Body: The action to be done by this method

Hint that the method defined should be the same as main at the unified level, with no relationship, method written in class

The parameter list at the time of the method definition is called--formal parameter list--formal argument

The argument list is called when the method is called--the actual argument list--argument

Does the variable name of the formal parameter and argument need to be consistent? -No need

Method overloads:

Methods in Java that have multiple identical method names but different parameter lists in the same class

When the number of arguments is the same and has different data types, sometimes the order also causes the method overloads to be independent of the return type

What the constructor does: Create the object and initialize the property

Use of constructors: New key constructor name ()

If there is no writing constructor in a class, the class implicitly adds a constructor with no arguments and no statements

Structure: Access modifier class name (argument list) {method body}

Constructors without parameters--non-parametric constructs

Constructors with parameters--a parametric construct

This

1. Refers to the current object this. To invoke the properties and behaviors in this class

2. Can refer to a constructor in the current class this (parameter list)

Java Basics and Javaoo section Summary

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.