File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Doubt in Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Doubt in "this" Key word" Watch "Doubt in "this" Key word" New topic

Doubt in "this" Key word

Vijay Sharma

Joined: Oct 12, 2005
Posts: 17

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)

else if (src == button2)


Cheers,<br />Vijay Sharma
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2398
this just means the current instance. so you are calling those methods in the instance of the ActionListener.
Vijay Sharma

Joined: Oct 12, 2005
Posts: 17
Thanks Keith!!
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

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.

The Best way to predict your future is to create it - Every great individual common man
I agree. Here's the link:
subject: Doubt in "this" Key word
It's not a secret anymore!