Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-31-2007, 07:21 PM
Member
 
Join Date: Jul 2007
Posts: 41
paty is on a distinguished road
what does "this" mean?
I know that is a silly question but I am looking for a definitive answer. I have used it but I can't explain it.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-31-2007, 07:57 PM
Member
 
Join Date: Jul 2007
Posts: 72
Swamipsn is on a distinguished road
Hi,
"this" means you indicates the variable or instance which is used by this[Present] class. Suppose your base class have int x, and derived class also have int x then you need to use this key word to point out the derived class's
x. .....
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-01-2007, 06:38 AM
Member
 
Join Date: Aug 2007
Posts: 15
yiweiang is on a distinguished road
Hi there, let me give you an example of "this" that will help you grasp this concept better. Assume you have a class, called Dog. The Dog has three variables, age, height and weight. And you have a constructor:

public class Dog
{
int age;
int height;
int weight;


public Dog(int age, int height, int weight)
//Constructor. The calling method will parse int age, height and weight
{
/*
So this is the problem. both variables have the same name! age that is passed in and age that is the class variable! so to solve it, you use "this"*/

this.age=age;
this.height=height;
this.weight=weight;
}
}

So in the three lines of "this.age" "this.height" and "this.weight". it sets the CLASS variable, the one declared in the lines right after the class declaration to the three integers that are passed in.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-01-2007, 06:45 PM
Member
 
Join Date: Jul 2007
Posts: 41
paty is on a distinguished road
thanks guys
yiweiang you were very clear
It was driving me crazy
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
failure at Class.forName("oracle.jdbc.driver.OracleDriver"); RonNYC Eclipse 1 03-14-2008 04:51 PM
Hwlp with "Open", "Save", "Save as..." trill New To Java 1 07-31-2007 09:53 AM
Exception in thread "main" java.net.ConnectException: Connection timed out osval Advanced Java 1 07-28-2007 12:59 AM
Error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException romina New To Java 1 07-26-2007 12:55 AM
ArrayList: Exception in thread "main" java.lang.NullPointerException susan New To Java 1 07-16-2007 08:32 AM


All times are GMT +3. The time now is 11:25 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org