File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OutPut of abstract class constructor calling method

 
abhijit Ohal
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sujittt Tripathyrr
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Question abhijit ..

thanks
 
abhijit Ohal
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Satou
 
Douglas Chorpita
Ranch Hand
Posts: 97
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Great question!!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic