| Author |
CoreJava
|
sukhavasi vasavi
Ranch Hand
Joined: Jul 18, 2007
Posts: 59
|
|
When this keyword is used? Shall we define default constructors necessarily,if we defining argument constructor in the extending class
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Not an ORM question. Moving...
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32704
|
|
The keyword this refers to whichever object you happen to be in at present. Several common uses:- 1: Send a reference to the whole object, eg when serialising . . . objectWriter.writeObject(this);Refer to the attributes corresponding to the object. Example. In a constructor public Foo(String name){ . . . this.name = name;. . .}To get a reference from an inner class object to the object of its surrounding class write "OuterFoo.this"Not absolutely essential, but you can use to to distinguish your present object from another object of the same class . . . if(this.foo.equals(other.foo))And there are bound to be other occasions . . .
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32704
|
|
|
. . . and welcome to the Ranch.
|
 |
Saathvik Reddy
Ranch Hand
Joined: Jun 03, 2005
Posts: 228
|
|
Originally posted by sukhavasi vasavi: Shall we define default constructors necessarily,if we defining argument constructor in the extending class
Yes! [ July 18, 2007: Message edited by: Sheethal Reddy ]
|
 |
 |
|
|
subject: CoreJava
|
|
|