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