• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inheritance: what's the output?

 
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
Marshal
Pie
Posts: 21430
84
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic