Functions of Java

Source: Internet
Author: User

How to define a function
1, the function is a separate function, first of all to clarify what the function of the results of the operation, that is, the function of the return value type.
2, clearly define the function of whether the process requires unknown content to participate in the operation, that is, the definition of the function of the parameter list (the type of parameters and the number of parameters).

Overloading of functions
Definition: The function name is the same, the parameter list is different.
The parameter list is different, that is, the parameter types are different and the number of parameters is different. Overloading and return value types are not related.

When to use overloading
When the functions defined are the same, but the unknown contents of the participating operations are different.
Then, a function name is defined to represent the function, which is easy to read and distinguishes multiple functions with the same name by different argument lists.

constructor function
Characteristics:
1, the function name is the same as the class name
2. Do not define return value types
3, can not write return statement

Covered:

1, the subclass overrides the parent class, you must ensure that the child class permissions are greater than or equal to the parent class permission before overwriting, or the compilation fails.

2, static can only be overridden by static.

Building code Blocks
Function: initializes the object.
The object runs as soon as it is established, and takes precedence over the constructor execution.

And the difference between the constructor function:
Constructing a code block is a unified initialization of all objects,
The constructor is initialized to the corresponding object.

The initialization of different object commonalities is defined quickly in the construction code.

Format:

{
System.out.println ("Hello");
}

Static code block
Format:
Static
{
EXECUTE statement
}
Feature: Executes only once when the class is loaded.
Function: Used to initialize a class

Object initialization Process
Person p = new person ("Zhangsan", 20);

What has been done in this sentence?
1, because new uses the Person.class. So the Person.class file is found and loaded into memory first.
2, executes the static block of code in the class, and, if any, initializes the Person.class class.
3. Open space in heap memory and allocate memory address.
4, the unique properties of the object are established in heap memory. and the default initialization.
5, the properties are displayed initialized.
6, the object is constructed with code block initialization.
7, initialize the corresponding constructor for the object.
8, the memory address is paid to the P variable in the stack memory.

Functions of Java

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.