Solved

What does "this" do in this Java class?

Posted on 2007-03-28
1
172 Views
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;
      }
}
0
Comment
Question by:yankeebushsoftware
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
reach2piyush earned 500 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
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to implement Singleton Design Pattern in Java.
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

623 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