Construction method, this key another use

Construction method

      All // constructor first line there is a default statement super ();

Attention to the problem:

 1. When you do not write the constructor, your compiler will automatically give you add an empty parameter configuration .public Person () {}

2. When you write a constructor method, the compiler will not give you added

 

 

n name of the constructor must be consistent with the class name.

 

Review small (this is to distinguish member variables and methods the same name localized, this statement is the name of this class variables)

The structure is best to write some because an empty argument constructor constructor can only be called for the first time when the new method, later if they wish

 

 

 

 

to sum up:

Constructor when the object is created on the implementation, and it is performed only once. Constructor does not return

General approach is after the object is created, if need be invoked objects, and can be called multiple times.

Constructor name must be consistent with the class name.

Another use this keyword

 

this can only be done between the present call class constructor method called only on the first line

Different inside this and super with a constructor, but indirect call super ()

 

 

Guess you like

Origin www.cnblogs.com/pandam/p/10960197.html