Java this Keyword

Java this Keyword:

We can use the Eclipse IDE for this example. If you do not know about it then follow this link- How to Install Eclipse For Java and create a program in it.

Keyword “THIS” in Java is a reference variable that refers to the current object. The various usage of the keyword Java “This” in Java is as per below,

  • It can be used to refer current class instance variable.
  • It can be used to invoke or initiate current class constructor.
  • It can be passed as an argument in the method call.
  • It can be passed as argument in the constructor call.
  • It can be used to return the current class instance.

Example of Java this Keyword:

Java this Keyword Codeunit
public class Main {
	int x = 6;
	int y = 4;
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	   new Main().add(6,4);
	public Main add(int x, int y) {
		System.out.println("x + y = "+ this.x + this.y);
		return this;


Tutorial MySQL
Tutorial Python
Object-Oriented Programming (OOP)
Structured Programming- Advantages and Disadvantages
Continue Statement in C Language
Spooling and Virtual Devices
Information Security in E-Commerce
Client-Server Architecture
Java (programming language)– Wikipedia

Comments (No)

Leave a Reply