Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2005

Tip: Looking for answers? Try searching our database.

"this" statement?

Thread view: 
JS - 17 Jan 2005 19:22 GMT
The "this" statement that is used in the method "exitRoom" and "explore" is
that synonymous with an "Explorer" object?

public class Explorer implements PlayerBehavior {

   private String my_name;
   private String my_secret_word;
   private RoomBehavior where_I_am_now;

   public Explorer(String name, String word){

       my_name = name;
       my_secret_word = word;
       where_I_am_now = null;

     }

   public String speak(){

       return my_secret_word; }

   public void exitRoom(){

       if ( where_I_am_now != null )
          { where_I_am_now.exit(this);
            where_I_am_now = null;
          }
     }

   public boolean explore(RoomBehavior r){

       if ( where_I_am_now != null )
          { exitRoom(); }

       boolean went_inside = r.enter(this);
       if ( went_inside )
          { where_I_am_now = r; }
       return went_inside;
     }

   public RoomBehavior locationOf(){

       return where_I_am_now; }
   }
Thanasis \(sch\) - 17 Jan 2005 22:03 GMT
exactly. this means the current object of Explorer class

> The "this" statement that is used in the method "exitRoom" and "explore"
> is
[quoted text clipped - 41 lines]
>        return where_I_am_now; }
>    }
JS - 18 Jan 2005 09:49 GMT
Is it possible to write the "explorer" method without using "this" and how
would it look?

"Thanasis (sch)" <thanasis_gr@hotmail.com> skrev i en meddelelse
news:41ec360d$1@news.sch.gr...
> exactly. this means the current object of Explorer class
>
[quoted text clipped - 43 lines]
> >        return where_I_am_now; }
> >    }
Thanasis \(sch\) - 18 Jan 2005 22:59 GMT
what is the code for RoomBehavior?

> Is it possible to write the "explorer" method without using "this" and how
> would it look?
[quoted text clipped - 51 lines]
>> >        return where_I_am_now; }
>> >    }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.