• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding constructors  RSS feed

 
kris na
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
 
Ben Souther
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.
 
Raghavan Muthu
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!