loading......

coming soon

Coming Soon

We are in process of building the inventory of good professionals in this category

Got it!

Where do you need ?

location

Please select a Location.

IT Courses/Java

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

Asked by Last Modified  

Answer
Follow 5

Please enter your answer

8 Answers   1 Likes | 0 DisLikes

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

"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

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

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

POST YOUR REQUIREMENT NOW

Java Professional

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.

Comments
Dislike Bookmark

'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

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

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 an argument in the method call 'this' can be passed as argument in the constructor call

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
Related Questions

IT Courses/Java

Why we are using this keyword in Java?

Asked by Kiran Bulkquestions 11 Jul

Answer 6
Follow 4
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 Jul

Answer 9
Follow 5
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 Jul

Answer 6
Follow 3
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 Jul

Answer 5
Follow 2
Answer submitted successfully. ×

Please enter your answer

IT Courses/Java

Which programming language should one use for large scale machine learning, Java or C++?

Asked by Rayaan Bulkquestions 11 Jul

Answer 5
Follow 0
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

Session Tracking In Java Servlets

Session Tracking: HTTP is a stateless protocol. Each request is independent of the previous one. However, in some applications, it is necessary to save state information so that information can be collected from several interactions between a browser...

Core Java

Introduction: An Object Oriented Programming Language consists of Objects. There are object oriented programming languages like Smalltalk, C++. Each and every OOP language has some underlying disadvantages. C++ has some disadvantages like Security, Robust...

What Is The Exact Life Cycle Of A Servlet?

Java : Command Line Arguments

The parameters which are provided to the program at the command line. Eg:d:\>java a 10 20 30 Here,“java” is an interpreter, “a” is filename,10,20,30 are arguments passed to the program while executing the program And the notation...

Why Should We Learn Java Language?

Most of starters has confusion today that which of the programming language should be chosen to work on. It totally depends upon your need. As per my opinion, if you want to grow your career in IT industry it is good to choose Java Language because of...

Sponsored

Find Best Java Training Classes?

Find Now »