• Post Reply Bookmark Topic Watch Topic
  • New Topic

Initializing sub class .How many instance..?  RSS feed

 
Karan V Praba
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a class called A which extends class B.When I create instance of Class A, how many instance will be created?
Is it two?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you create an instance of A you get just that - an instance of A. Internally the JVM has to load the code for class B and allocate memory for its variables, and we could argue about whether that is "an instance" but that's not really information you want to worry about or make use of. Part of learning OO is learning to let go of the things you're not suppposed to worry about. It's hard if you're used to owning all the code but it makes life a lot easier in the long run.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!