• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

CoreJava

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When this keyword is used?
Shall we define default constructors necessarily,if we defining argument constructor in the extending class
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not an ORM question. Moving...
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
    Marshal
    Posts: 79180
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    . . . and welcome to the Ranch.
     
    Ranch Hand
    Posts: 228
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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 ]
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic