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 Using super and this in the constructor together Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Using super and this in the constructor together" Watch "Using super and this in the constructor together" New topic
Author

Using super and this in the constructor together

Ayumu Osamu
Greenhorn

Joined: Dec 17, 2010
Posts: 4

I always thought that the first line in the constructor is either a super() or a this(). However, this code gives me unexpected output.


And outputs:


Why is it so?


SCJP6/OCPJP 6.0
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

The this() call in the 2nd constructor will call the 1st constructor (the no-arg one) and the first constructor will call the super constructor. As simple as that


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ayumu Osamu
Greenhorn

Joined: Dec 17, 2010
Posts: 4

Ankit Garg wrote:The this() call in the 2nd constructor will call the 1st constructor (the no-arg one) and the first constructor will call the super constructor. As simple as that


Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using super and this in the constructor together