Solved

What does "this" do in this Java class?

Posted on 2007-03-28
1
170 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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 106
Not seen Link button 5 58
Eclipse Java import and method not resolved 4 52
wild fly 8 startup error 2 14
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

821 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