Solved

toString method

Posted on 2014-02-28
2
231 Views
Last Modified: 2014-02-28
Hi,

In the java classes, is it common to write this.variable in the toString method when you are overriding it. Why is "this" written? You are able to access the variable without this.
i.e
public class test{
private String a;

@Override
      public String toString() {
return this.a;
}
}
0
Comment
Question by:zizi21
2 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 39896336
You only really need to use the 'this' keyword if the variable is shadowed by a method or constructor parameter see :

http://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html
0
 

Author Closing Comment

by:zizi21
ID: 39896348
Thanks !
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This video teaches viewers about errors in exception handling.
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 …

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now