• Post Reply Bookmark Topic Watch Topic
  • New Topic

Code behaving different than I expected.  RSS feed

 
Shelby Simpson
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I run the code below it prints out both "MySuper" and "MySub". I thought for sure it would just print "MySub". I'm confused to what is going on here.?

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any constructor¹ that doesn't explicitly start with a call to another constructor in the current class ( this(...) ) or a call to a superclass constructor ( super(...) ) has an implicit call to super() added by the compiler.

So this:


is equvalent to this:



¹Except for Object's no-arg constructor
 
Shelby Simpson
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see, thanks I appreciate it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!