• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Subclass calls super class constructor then how many object will be created

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If Sub class calls the super class constructor. Then if i create the object of subclass then how many object or memory will be created.
suppose ClassA extends ClassB, ClassB extends ClassC, ClassC extends ClassD
i created the object of ClassA(new ClassA()) then how many object will be created.

Thanks,
Regards,
Amit
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amitt. Welcome to The Ranch!

Just one. That one object IS-A ClassA, ClassB, ClassC and ClassD.

(Moving to Beginning Java)
 
Amitt Thakkarr
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Mathew.. Thanks..
But i wanted to know if subclass will call the super class constructor by default then how memory created for each constructor...
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will call the superclass constructor, but only to carry out any initialisation that the superclass requires. It doesn't create another object. Constructors don't directly create objects; rather, all the relevant constructors are called when an object is created.

How much memory? It depends on what the superclass constructor does. Possibly none.
 
We've gotta get close enough to that helmet to pull the choke on it's engine and flood his mind! Or, we could just read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic