Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Danielle Daniels   on Jun 01 In Java Category.

  
Question Answered By: Gerardo Morgan   on Jun 01

"This" can be explained very simply. It is simply a reference to the
particular instance of an object you call a method on. When you call
a methjod, for example:

lemon.squeeze();

the "this" pointer is passed as an invisible argument - the memory
address of the particular object instance, so the operation is
performed on the correct object - and this is why static methods do
not pass the "this" pointer as they sit outside the object hierarchy -
which is why you get those error messages when you try and refer to
instance data from a static block.

"This" is also used in an idiosyncratic way inside constructors.

Share: 

 

This Question has 4 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on help me to understand "THIS" key word Or get search suggestion and latest updates.


Tagged: