1. Construction method
This refers to an object that is called to initialize the constructor method.
// with a reference structure Public int Age ) { this (); // call no parameter constructs // This (name); // Call the constructed method with the parameter name this. Name = name; this. age= age ;}
2. Common method (non-static method)
This refers to the object that called the method.
// Common Methods Public void setName (String name) { this. Name = name;}
Why can I use the this keyword in constructors and normal methods?
--this is an implicit parameter, and the system automatically passes a This parameter (a reference to the invoked object) when the method is called, but is implicitly passed (super-similar).
Why can't I use the This keyword in a static method?
-- The static method may not be called by the object (e.g., called directly by the Class), so this does not have an object to reference.
Use of the This keyword in Java