• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

super(x,y) and this() in one constructor

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this:






You see, I want to call a super-constructor and a this-constructor within a constructor of a sub-class. Why does this not work?

The debugger says:

"Constructor call must be the first statement in a constructor"

Changing the order of super() and this() within the constructor does not help.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can either have a super() or this() not both. The error states why. Both calls another constructor and that should be the first line in your constructor code.
 
Matthew Brown
Bartender
Posts: 4565
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nimo frey wrote:


You can get what appears to be the effect you want like this, without violating the rules:
 
Campbell Ritchie
Sheriff
Posts: 48378
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But in real life, avoid passing nulls as far as possible.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic