File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
nimo frey
Ranch Hand
Posts: 580
  • 0
  • 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
  • 0
  • 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: 4549
8
Java Netbeans IDE Scala
  • 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
Pie
Posts: 47244
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But in real life, avoid passing nulls as far as possible.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic