hi guys.. i have read from kathy book that 'INSTANCE MEMBERS ARE ACCESSIBLE ONLY AFTER THE SUPER CONSTRUCTOR RUNS', i have tried a lot to understand what that have meant, but could not understand.. can anybody help me please..
I think he is not getting the concept itself, the code can make him understand better..but we need some theory to get what is actually going on... so here it is...
Instance members are associated to the object rather than the class. So to access an instance member you first have to tell JVM which object's instance memeber it is and for that the object needs to be in existance ( i.e. in memory). Whenever you create an object say like this..
Box b = new Box();
then unless the constructor ( and the constructors of all super classes class Box inherits from) completes the object doesnt come to life...its yet to take birth. Hence before the constructors complete their job you don't even have the object, then how can you access its member? You can't kiss the baby before its born!
I hope you understand now.. to confuse you more ( actually to make you understand in better way) you can call the static members of the class from constructors... now start thinking why... you will understand the concept.
Now please execute the code my friend gave above..
Originally posted by venkatesh badrinathan: Thanks Mr.seetharaman.. i have understood now.
oopss.. venkatesh..my post was just 7 minutes after yours..so i didnt know you got it when I was posting it.. anyways..its good you got it.
Joined: Aug 03, 2008
thanks Mr.Saurabh Patil, your explanation was excellent, i am now clear about the concept that i could explain to anyone and also, accessing static members from constructors is possible because we dont need an object to access static members, hence we do. i think i am right...???
Originally posted by venkatesh badrinathan: thanks Mr.Saurabh Patil, your explanation was excellent, i am now clear about the concept that i could explain to anyone and also, accessing static members from constructors is possible because we dont need an object to access static members, hence we do. i think i am right...???