Java Learning Note day04

Source: Internet
Author: User

1.static keywords
Features: 1) loaded with the load of the class
2) precedence over object existence
3) shared by all objects
4) can be called directly by the class name (class name. Static members)

Note: Static methods can only access static members.
Non-static methods can access both static and non-static members.
In a static method, the This,super keyword cannot be present.

Static code block:
1) executes as the class is loaded and executes only once, prior to the main function execution
2) Function: class initialization
If there is only {} In the class, there is the execution code, it is the instance code block, followed by the instance, how many instance objects there are, how many times will it execute.

2.this Keyword: Represents an object that represents a reference to the object to which this function belongs.
Which object calls the function where this is located, and this represents which object.
Another way to call a constructor is to use this
Format: This ("", "" ",..); Can only be placed on the first line of code.
Such as:

 class   person{ private   String name;  private  int   age; Person (String name,  int   age) { Span style= "color: #0000ff;"        >this . Name = name;      this  ("Zhang San", 18 = "MyName" ;    SYSTEM.OUT.PRINTLN ( person run ); }}

3. Constructors:
Feature: function name is the same as class name
As long as the class is defined by default, there is an empty argument constructor, which is implicit.
Default constructor:
Class name () {}
When a custom constructor is defined in a class, the default constructor is gone.

Operational features: object creation invokes the corresponding constructor
Function: initializes the object.

Java Learning Note day04

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.