Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 26th, 2005, 7:01 PM   #1
thenewkid
Programmer
 
Join Date: Sep 2004
Location: New Jersey
Posts: 36
Rep Power: 0 thenewkid is on a distinguished road
Send a message via AIM to thenewkid
Question parameter 'this' ???

hey...
i was reading the text which our school require us to read...this book mentioned something about the "this" parameter, which is a hidden parameter passed to the methods or any other stuff that need the reference to the object......i was thinking that if i would be able to return this variable from the method i could reference some object created by this method....my question is how do i do it....i was trying many stuff...i have also checked the web for this ....."this" word is to common to be searched by the engines ..at least some of them...lol...
help me if u can!!!
thanx in advance!!!!!
thenewkid is offline   Reply With Quote
Old Jan 26th, 2005, 8:29 PM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
If you have a class with local parameters, they can be accessed with the 'this' method. 'this' is just an identification method pointing to the current object. For instance, when programming a class... the current object is that class. Basically, when programming classes(or objects) the 'this' keyword acts as a pointer to the inherited traits of the object when in use by the program (sigh i know that made no sense). Even more basically, its used when programming classes to say to call itself as if someone who used it in the program would under the variable they declared, in place of the variable they declared you can call internally the functions of your class with the 'this' keyword (if that made any sense).

I give up.
__________________


Last edited by tempest; Jan 26th, 2005 at 8:34 PM.
tempest is offline   Reply With Quote
Old Jan 27th, 2005, 12:16 PM   #3
Hockeyman
Programmer
 
Hockeyman's Avatar
 
Join Date: Jan 2005
Location: Vancouver, Canada
Posts: 60
Rep Power: 4 Hockeyman is on a distinguished road
Send a message via MSN to Hockeyman
I could be off-base here, never having programmed in Java - but this sounds like the "this" in C++....so....
You have a class you've called "DrinkingBuddy". This class has a few attributes (like name, age, colour, etc) and a few methods (like drink(), puke(), and passout())....so you instantiate an object of your DrinkingBuddy class called "Todd". You then call the drink() method using your Todd object (Todd.drink(rum) ) - in the drink() method code, if you wanted to refer to the todd object (say to specify an attribute) you would say "this->colour = green;" (the actual java code would probably be different, but you get the idea)....so the "this" refers to the Todd object. If you later instantiated another DrinkingBuddy object called "Jeff", and used the drink() method, the "this" would then refer to the "Jeff" object, as that was the one that called it.
To answer your question - because the "this" refers only to the object that called the method the "this" actually appears in, you couldn't use it to pass that object around...

I hope that makes sense for Java...(or for C++ for that matter) - if not, please correct me.
__________________
~ You know, Hobbes, some days even my lucky rocketship underpants don't help. ~

Hockeyman is offline   Reply With Quote
Old Jan 27th, 2005, 5:51 PM   #4
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Looks like a great explanation to me...
__________________

tempest is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:10 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC