File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in "this" Key word

 
Vijay Sharma
Greenhorn
Posts: 17
  • 0
  • 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: 2399
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Keith!!
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • 0
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic