| Author |
OutPut of abstract class constructor calling method
|
abhijit Ohal
Ranch Hand
Joined: Mar 10, 2006
Posts: 63
|
|
In Above Code int cnt = 1; then also output is zero. from new abs(3)called abstract class xyz ' constructor it call class abs 'm1 method What i am thinking is in that time cnt is not initalisied to 1 so it is giving output '0'.Can some one expalain in details.
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
Tricky. Class variable initializers and static initializers of the class will be executed after the superclass initialization. So when your println is called, members of the subclass are not initialized yet. That's why the default value (0 for an int) is output.
|
[My Blog]
All roads lead to JavaRanch
|
 |
Sujittt Tripathyrr
Ranch Hand
Joined: Jun 21, 2006
Posts: 96
|
|
Good Question abhijit .. thanks
|
 |
abhijit Ohal
Ranch Hand
Joined: Mar 10, 2006
Posts: 63
|
|
Thanks Satou
|
 |
Douglas Chorpita
Ranch Hand
Joined: May 09, 2006
Posts: 97
|
|
|
Yes. Great question!!!
|
SCJP 1.4 - 95%
|
 |
 |
|
|
subject: OutPut of abstract class constructor calling method
|
|
|