Basic computer course, C programming language, Education, Engineering Course, Engineering Courses, Maths Coaching, online computer coaching, PGDCA course coaching, programming course, school computer coaching, training, Uncategorized, Web Design course

Use of This keyword – tccicomputercoaching.com

There can be a lot of usage of this keyword. This is a reference variable that refers to the current object.

Here is given the 6 usage of java this keyword.

  • this can be used to refer current class instance variable.
  • this can be used to invoke current class method (implicitly)
  • this() can be used to invoke current class constructor.
  • this can be passed as an argument in the method call.
  • this can be passed as argument in the constructor call.
  • this can be used to return the current class instance from the method.

use of this keyword

There are main 3 usage of this keyword.

1) this: to refer current class instance variable 

The this keyword can be used to refer current class instance variable. If there is ambiguity between the instance variables and parameters, this keyword resolves the problem of ambiguity.

2. this: to invoke current class method

You may invoke the method of the current class by using the this keyword. If you don’t use the this keyword, compiler automatically adds this keyword while invoking the method. Let’s see the example

3. this() : to invoke current class constructor

The this() constructor call can be used to invoke the current class constructor. It is used to reuse the constructor. In other words, it is used for constructor chaining.

If you are interesting to learn coding then you can join computer course at TCCI in Bopal and Satellite in Ahmedabad.

Call us @ 9825618292

Visit us @ http://www.tccicomputercoaching.com

 

Leave a comment