Signup as a Tutor

As a tutor you can connect with more than a million students and grow your network.

IT Courses/Java

What is the use of the "this" keyword in Java?

Asked by Last Modified  

Answer
Follow 6

Please enter your answer

9 Answers   2 Likes | 0 Dislikes

'this' refer the current instance of a class. You can get and set data members of current object using 'this' prefix inside there class data type.
Comments
Dislike Bookmark

Java J2ee Spring Angular JS Training

The 'this' keyword in Java is a reference variable that refers to the current class object. 'this' keyword can be used to refer current class instance variable 'this' can be used to invoke or initiate current class constructor It can be used to return the current class instance 'this' can be passed as... read more
The 'this' keyword in Java is a reference variable that refers to the current class object. 'this' keyword can be used to refer current class instance variable 'this' can be used to invoke or initiate current class constructor It can be used to return the current class instance 'this' can be passed as an argument in the method call 'this' can be passed as argument in the constructor call read less
Comments
Dislike Bookmark
class xyz{ int x; int y; xyz (int x,int y){ this.x=x; this.y=y; } Used to specify current class object
Comments
Dislike Bookmark

Join Urbanpro.com, India?s most trusted education portal for your learning requirements

POST YOUR REQUIREMENT NOW
"This" is a keyword it refers to the current object E.g if your method variable name is same as your reference variable name then we use "this" keyword to tell the compiler that i am using reference variable not method variable For Core Java Training You can visit and Send a Enquiry on my Profile... read more
"This" is a keyword it refers to the current object E.g if your method variable name is same as your reference variable name then we use "this" keyword to tell the compiler that i am using reference variable not method variable For Core Java Training You can visit and Send a Enquiry on my Profile on UrbanPro http://ubpro.in/C67fasiy Vivek read less
Comments
Dislike Bookmark

In java 'this ' keyword is used to access property of current class eg. using 'this' keyword current iinstance variable of class is accessible.
Comments
Dislike Bookmark
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... read more
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. read less
Comments
Dislike Bookmark
Keyword 'THIS' in Java is a reference variable that refers to the current object. It can be used to refer current class instance variable.
Comments
Dislike Bookmark
actually "this" keyword resolve the ambiguity between the current instance variable and the constructor parameter, also keeping both the parameters with same name is not a good practice anymore as well. So better way is to make your constructor parameter with name starting with "p" where "p" stands for... read more
actually "this" keyword resolve the ambiguity between the current instance variable and the constructor parameter, also keeping both the parameters with same name is not a good practice anymore as well. So better way is to make your constructor parameter with name starting with "p" where "p" stands for parameter. In that case your code will run with out "this" as well. read less
Comments
Dislike Bookmark
"this" is a refernce variable that refers to the current object. "this" keyword is used to refer current class instance variable in a conctructor and a method which has called the method.
Comments
Dislike Bookmark
Related Questions

IT Courses/Java

Why we are using this keyword in Java?

Asked by Kiran Bulkquestions 11/07/2017

Answer 7
Follow 5
Answer submitted successfully. ×

Please enter your answer

IT Courses/Java

What is the purpose of using throws keyword in java?

Asked by Saritha Bulkquestions 11/07/2017

Answer 10
Follow 8
Answer submitted successfully. ×

Please enter your answer

IT Courses/Java

Is synchronized keyword necessary, in Java, if everything that is modified in a function is local to that function?

Asked by Abishiek Bulkquestions 11/07/2017

Answer 5
Follow 1
Answer submitted successfully. ×

Please enter your answer

IT Courses/Java

What programming languages should a freshman learn if he already knows C, C++, Java and Python?

Asked by Sushmita Bulkquestions 11/07/2017

Answer 7
Follow 5
Answer submitted successfully. ×

Please enter your answer

IT Courses/Java

Which is the best programming language to learn in today's era? Java, C,C++, Python or any else?

Asked by Swati Bulkquestions 11/07/2017

Answer 5
Follow 3
Answer submitted successfully. ×

Please enter your answer

Looking for a Tutor?

Find best Tutors in your locality on UrbanPro.

FIND NOW

Now ask questions in any of the 1500+ Categories, and Get Answers from Tutors on UrbanPro.com

ASK A QUESTION

Related Lessons

Java Interview Questions & Answers

Java Interview Questions have been designed especially to get you acquainted with the nature of questions you may encounter during your interview for the subject of Java Programming Language. As per my experience, good interviewers hardly planned to ask...

What Is Java? Explain The History Of Java

i. Ovierview: Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java platform (Java 1.0 [J2SE]). The latest release of the Java Standard...

Thread Class In JAVA

Thread Class: Thread class is the main class on which Java's Multithreading system is based. Thread class, along with its companion interface Runnable will be used to create and run threads for utilizing Multithreading feature of Java. Constructors of...

Understanding Object Serialization In Java

Simple walkthrough: What is Serialization? Converting an object to bytes and bytes back to object (Deserialization): When is serialization used? When we want to Persist the Object. When we want the object to exist beyond the lifetime of the JVM: Real...

Crux Of The Basic Interview Question Asked Around It Professionals

Question: Explain PSVM() [Public Static Void Main()] in Java. Answer: This question is asked from a differnet persctive. Person asking this question is looking for deep java concepts. If answer in your mind is something like this, "Public is used so that...

Sponsored

Find Best Java Training Classes?

Find Now »