This week's book giveaway is in the Agile forum.
We're giving away four copies of The Software Craftsman and have Sandro Mancuso on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark ""this" and "super"" Watch ""this" and "super"" New topic

"this" and "super"

Rajiv Goyal

Joined: Jul 28, 2003
Posts: 25
Sometimes confused with these key words?Can you please:
a)Let me know salient features of both "separately"
b)Differnce between two
Damien Howard
Ranch Hand

Joined: Apr 01, 2003
Posts: 456
Let me know salient features of both "separately"
"this" is an implicit reference to the current object. all Objects have a this reference. It can be used to pass a reference to the current object to a method in another object.
super is used to refer to the parent class of the current object. This is useful if you wish an overriding method to refer to the version of the method in the parent class.
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

also this() and super() play a key role in constructor.
Check out the JLS for more info and a lil example: �8.8.5 Constructor Body
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1090
Hi Rajiv
There is no this in a static reference, for example the main() method.
[ August 08, 2003: Message edited by: Anupam Sinha ]
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: "this" and "super"