File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes OutPut of abstract class constructor calling method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "OutPut of abstract class constructor calling method " Watch "OutPut of abstract class constructor calling method " New topic
Author

OutPut of abstract class constructor calling method

abhijit Ohal
Ranch Hand

Joined: Mar 10, 2006
Posts: 64

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: 14688
    
  16

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: 64
Thanks Satou
Douglas Chorpita
Ranch Hand

Joined: May 09, 2006
Posts: 97
Yes. Great question!!!


SCJP 1.4 - 95%
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: OutPut of abstract class constructor calling method