• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is it possible to invoke super() as well as this() in a constructor?  RSS feed

 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is this not valid in java? I got both super() or this() should be the first in the statement

 
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry i misread. I think both cannot be used together. I am getting same error. No idea why but roughly i thought by using both your are calling super constructor twice which is not possible.
 
Marshal
Posts: 56603
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you write super(); this(); then this(); is the second statement. If you write this(); super(); then super(); is the second statement.

Both must be in the first statement, so you can only use one at a time.
 
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need to put this() and super() in the same constructor?
 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By mistake, I replied to this srry.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!