After barreling through a lot of advanced concepts in Java, here is a another often confused and puzzling one – the ‘this’ keyword…:)

Keywords in Java:

Before we get to see the ‘this’ keyword, let us discuss the numerous keywords in Java. ‘Keywords’ are special words in Java which are there for a special purpose. Some examples of keywords are:

abstract, final, finally, new, synchronized, super, long, implements, this and more.

Important point:

‘Keywords’ cannot be used as identifiers for any Java program. That is, the keywords in Java cannot be used to name any class, method or variable. They can only be used for their purpose.

‘this’ keyword:

Maybe the most puzzling keyword is the ‘this’ keyword in Java.

In absolutely simple terms, ‘this’ is the current instance of Java.

The ‘this’ keyword can be used with a constructor

The ‘this’ keyword is used to avoid overshadowing by other variables(as local variables taking precedence in some cases)

Let us see a simple program to illustrate the ‘this’ keyword…

 

Join me tomorrow as the Java marathon continues…:)

I’m participating in #BlogchatterA2Z by Blogchatter 

(Visited 41 times, 1 visits today)

Related Posts

2 thoughts on “‘this’ keyword in Java

Leave a Reply