aspose file tools*
The moose likes Java in General and the fly likes super(x,y) and this() in one constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "super(x,y) and this() in one constructor" Watch "super(x,y) and this() in one constructor" New topic
Author

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

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
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
Bartender

Joined: May 31, 2011
Posts: 1776
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

Joined: Apr 06, 2010
Posts: 4420
    
    8

nimo frey wrote:


You can get what appears to be the effect you want like this, without violating the rules:
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
But in real life, avoid passing nulls as far as possible.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: super(x,y) and this() in one constructor