- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
What are all the ways keyword ‘this’ can be used in Java?
You can use this keyword to –
- Differentiate the instance variables from local variables if they have same names, within a constructor or a method.
class Student { int age; Student(int age) { this.age = age; } }
- Call one type of constructor (parametrized constructor or default) from other in a class. It is known as explicit constructor invocation.
class Student { int age Student() { this(20); } Student(int age) { this.age = age; } }
- Related Articles
- What are the 6 ways to use this keyword in Java?
- What are all the ways an object can be created in Java?
- Can a "this" keyword be used to refer to static members in Java?\n
- Why "this" keyword cannot be used in the main method of java class?
- What are the uses of this keyword in java?
- What are the different unit values that can be used with MySQL INTERVAL keyword?
- Can a final keyword alone be used to define a constant in Java?
- Can we call methods using this keyword in java?
- This keyword in Java
- What are the different ways the transaction can be executed(DBMS)?
- Can we return this keyword from a method in java?
- Can we use "this" keyword in a static method in java?
- What is the keyword used in instantiating a class in Java?
- What can another keyword be used instead of MODIFY to modify the column/s of MySQL table?
- What are the two ways in which cow-dung can be used as a fuel? Which of them is better and why?

Advertisements