• 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

this() and super()

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Someone written that this() and super() must be the first line of any constructor, so this means that if they both came in the same class, then who is going to get the first statement within the constructor, or this means that the java doesnot support the referring of both the superclass and object default construtor from a constructor.
Please Help
Nisheeth KAUSHAL
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you cant use this() and super() together.
like u said, u have to choose only one of them if u wan to use them.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moreover, what's the point in using both this() and super() in a constructor? When you create a new object you have to create its superclass too. So, at one time or another super() will be called, either explicitely by you or implicitely by the compiler. If you call it yourself, you can decide whether you want to pass in some arguments to the superclass constructor or not, otherwise the default no-arg constructor of the superclass is invoked.
 
reply
    Bookmark Topic Watch Topic
  • New Topic