Statement: The material used in this column is written by the VIP students of the Kay Academy, who has the right to be anonymous and has the final right to interpret the article; The Edith Academy is designed to promote students to learn from each other on the basis of public notes.
The constructor reloads:
Constructors, like methods, are changes in methods.
Constructor overloading is the same as a method overload: The method name is the same as the parameter type or number of arguments.
Constructor Overload declaration method:
String strings:
It is not stored in a fixed way, more and less to look at the contents of the storage to determine.
Strings provide multiple strings to meet different needs and create more ways.
Low version: String inside is a char array
High version: String inside is a byte array
Builder application:
This keyword: 1. The current object gives us the object that is currently being used in the instance member.
2. Names can be used in different regions
3 Nearest principle: The variable name used is always the first to consider the nearest
4. How do I get an object running instance members in an instance member? Write this to get the current running object
Names of different regions (instance members): the equivalent of name gives back name, so it makes no sense.
(static member) solution of the same name in different regions: with the class names. Point type, which is the attribute type, assigns the property type to the type in the method.
(instance member) solution of different region name scheme: How to get the current object in the instance method? So Java invented a keyword (this current object), through this can get the current object.
The example 1:this is a change, it only obtains the current value to run the object. So the new one object, this gets the object is "Xutao" object.
Example 2: The current object is new out of C, the Floret is given to name, so this gets the current object is C.
Example 3:TEST3 will error, TEST4 will not error.
Test3 is an instance member, it will have a dead loop, there is no time new when there is an object, the object has a new has to produce an object, so it will produce a dead loop.
Test4 is a static member, only one copy is loaded, and new TEST4 only produces one copy.
Java Basics-Constructor overloading & this keyword