This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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: 9400
    
  20

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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Using super and this in the constructor together
 
jQuery in Action, 3rd edition