aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Competition between “this”and “super” in 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Competition between “this”and “super” in constructor " Watch "Competition between “this”and “super” in constructor " New topic
Author

Competition between “this”and “super” in constructor

Malatesh Karabisti
Ranch Hand

Joined: Jul 28, 2010
Posts: 153



error : Constructor call must be the first statement in a constructor
Can any body explain the reason for error ?
Gian Franco
blacksmith
Ranch Hand

Joined: Dec 16, 2003
Posts: 977
Hi,

Have a look at this


"Eppur si muove!"
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

There should be one way to construct an object. If we allow to use it as you gave, how many ways are there to construct an object? Won't there be a ambiguity in those two ways as you gave?


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 543
    
    4

A super() call, as well as a this() call, calls a constructor and thus has to be the first statement in a constructor. If you put the super call first, the this call is not the first statement, and if you put the this call first, the super call is not the first statement, which will cause the compiler to complain.


Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Malatesh Karabisti
Ranch Hand

Joined: Jul 28, 2010
Posts: 153

Thanks All.
 
 
subject: Competition between “this”and “super” in constructor