|
The Java keywords this and super are closely related to the method invocation. The use of this and super keywords is twofold. They can be used:
As a reference to access the instance members or the superclass
members (as we have seen earlier in section 1.4.2)
OR
As a method name for calling the constructors of the class or its
superclass
The this keyword used within an instance method refers to the instance on which the method is called upon. Listing 1.3 illustrate usage of this and super to call constructors as well as to refer to the instance.

![]()
![]()
The this keyword is used as a method name for calling the other Car constructor which takes a String and an int argument from another constructor which does not take any argument. The keyword super is used to call super class constructor and also to access the inherited members of the superclass. For example, if the Car has Automobile as superclass and if Automobile has engineType as instance variable, Car can access it as super.engineType. We will learn more about this and super while discussing constructor overloading in chapter 11.