Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Inheritance: what's the output?  RSS feed

 
Leandro Coutinho
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Leandro Coutinho
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got surprised with the result. I thought instances of the super classes were always created before the child classes, but, based on the result, it seems that it is not what happen.
It's more like the not private members of the super class are included inside the child class, and you can use "super" and "this" more like a namespace ...
 
Henry Wong
author
Sheriff
Posts: 22818
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leandro Coutinho wrote:I got surprised with the result. I thought instances of the super classes were always created before the child classes, but, based on the result, it seems that it is not what happen.
It's more like the not private members of the super class are included inside the child class, and you can use "super" and "this" more like a namespace ...


Well... yeah. That's how it works. When you create an instance (with the new operator), there is only one instance. Large inheritance trees don't generate lots of objects..... And the private members of the super class are included too.

Henry
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!