Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in "this" Key word

 
Vijay Sharma
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I just want to know what does the this keyword performs in the following code?
public void actionPerformed(ActionEvent ae)

Object src = ae.getSource();
if (src == button1)

this.doButton1Action();
}
else if (src == button2)
{
this.doButton2Action();
}

}
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this just means the current instance. so you are calling those methods in the instance of the ActionListener.
 
Vijay Sharma
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Keith!!
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know what really difference between this and super keyword.
Actually this keyword can give you a object instance of current class. And super keyword never gives an object instance of super class. It's only use it to call method and constructer of super class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic