What does "this" do in this Java class?

Posted on 2007-03-28
Medium Priority
Last Modified: 2010-03-31
In this class what does "this do"

public class Lab {
      private long id;

      private String location;

      private String description;

      private String owner;

      public String getDescription() {
            return description;

      public void setDescription(String description) {
            this.description = description;

      public long getId() {
            return id;

      public void setId(long id) {
            this.id = id;

      public String getLocation() {
            return location;

      public void setLocation(String location) {
            this.location = location;

      public String getOwner() {
            return owner;

      public void setOwner(String owner) {
            this.owner = owner;
Question by:yankeebushsoftware
1 Comment

Accepted Solution

reach2piyush earned 2000 total points
ID: 18813386
Within an instance method or a constructor,
this provides a reference to the current object

In the following method
public void setDescription(String description) {
            this.description = description;

this.desciption points to the instance variable description
whereas just description refers to the local variable

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question