This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Howmany no of instances created in the inheritance tree?

 
Mihir Patel
Greenhorn
Posts: 18
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Please let me know that how many instance will be created in the inheritance tree if we create the instance of the subclass?

e.g.

class A{}
class B extends A{}
class C extends B{}

1) here if we create the instance of class C (C objC = new C()) then how many instance will be created?
2) if it'll create only 1 instance of class C then why it'll not create the instance of the base classes A and B eventhough it'll call the constructors of the base classes?

Thanks.
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will create 1 C object, which is also a B object and an A object (C IS-A B, B IS-A A).

A constructor doesn't create a new object. It initialises a new object that is created by the new operator. The A and B constructors will be called to carry out the initialisation associated with those classes.
 
Mihir Patel
Greenhorn
Posts: 18
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Brown!!!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic