• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Regarding constructors  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

1) classA extends Object
2) classB extends classA

now when i make a call new classB

constructor of classB is invoked which in turn calls constructor od classA which in turn calls constructor of Object

Object's instance variables are initalized first then
classA instance variables are initalized then
classB instance variables are initalized.

1) that means 3 objects are created ie of Object, classA & classB

or

2) all 3 constructor will initalize classB instance variables.

I think option 2 is correct ? please help
 
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"krishna n",
Please check your private messages.
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy "krishna n",

Welcome to JavaRanch

Before we could proceed with your question, let me take a moment to remind you of Ranch's Naming Policy which insists the people to use their *real names* which should contain their first name and last name separated by a space and they should obviously not be fictitious.

You can update your display name by editing your profile.
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by krishna n:
..
I think option 2 is correct ? please help



yes, but not exactly.

Only one object is getting created which is of type B, but all the other 2 constructors help their respective instance variables set which the newly created B's object is in need of.

So, Class B's constructor is responsible for initializing its variable and so the constructors of A and Object class.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!