File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 975
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
Ranch Hand

Joined: Aug 06, 2010
Posts: 359
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: Java EE 6 Web Component Developer
Oracle Certified Expert: Java EE 6 Enterprise JavaBeans Developer
Malatesh Karabisti
Ranch Hand

Joined: Jul 28, 2010
Posts: 153

Thanks All.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Competition between “this”and “super” in constructor
 
Similar Threads
Construcors
marcus Green question
MarcusMock No - 2 - Question 53.
Mock of Marcus Green
is it righ?