Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using super and this in the constructor together

 
Ayumu Osamu
Greenhorn
Posts: 4
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ayumu Osamu
Greenhorn
Posts: 4
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic