1. Exam Points
this keyword refers to the current object of a class.this can be used to distinguish an instance variable from a local variable with the same name.- this can be used to pass the current object as an argument to a method.
this can not be used in a static method.- Note:
- pay attention to
in which class this keyword is used.
2. Knowledge Points
(1) this Keyword
- Within an instance method or a constructor, the keyword
thisacts as a special variable thatholds a reference to the current object— the object whose method or constructor is being called. Class methods do not have a this reference,meaning that you can not use the this keyword in a class method.this keyword can be used to distinguish an instance variable from a local variable with the same name.- Example:
- Example:
- The keyword
thiscan be used topass the current objectas an argument in a method call.- Example:
- Example: