This Keyword

Inside the class body this refers to the current class object.

It can be used to access / modify members and call functions inside the class.

Example

Output:

Explanation:

  • At lines 13, 19 values are set to the members width and height.
  • At lines 25, 30 and 31 members are accessed.
  • At line 34 a class function is called.
  • At line 43 an object is created.
  • At lines 45 and 46 in which width and height are set, this points to the object created at line 43.