- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
This keyword in Java
Following are the usage of this keyword.
- this can be used to get the current object.
- this can be used to invoke current object's method.
- this() can be used to invoke current class constructor
- this can be passed as a parameter to a method call.
- this can be passed as a parameter to a constructor.
- this can be used to return the current object from the method.
Example
public class Tester { private String message; public Tester(String message){ this.message = message; } public void printMessage(){ System.out.println(message); } public static void main(String args[]) { Tester tester = new Tester("Hello World"); tester.printMessage(); } }
Output
Hello World
Here this keyword is used to get the current object and then gets its variable.
- Related Articles
- How to work with this keyword in Java?
- What are the uses of this keyword in java?
- Can we call methods using this keyword in java?
- ‘this’ keyword in C#
- Can we return this keyword from a method in java?
- Can we use "this" keyword in a static method in java?
- This keyword in Dart Programming
- When should I use the keyword ‘this’ in a Java class?
- What are the 6 ways to use this keyword in Java?
- Explain JavaScript "this" keyword?
- Is it possible to use this keyword in static context in java?
- What are all the ways keyword ‘this’ can be used in Java?
- Can we call a method on "this" keyword from a constructor in java?
- Why "this" keyword cannot be used in the main method of java class?
- Can a "this" keyword be used to refer to static members in Java?\n

Advertisements