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

what is the ouptut of this code??

 
Heba Mahmoud
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Given the following class, what is the value of Logger.logerCount after calling Logger.createInstance(-1) ?
why the output is 1 not zero??

and what about throwing exceptions while declaring a construtor
 
Henry Wong
author
Marshal
Pie
Posts: 20826
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the following class, what is the value of Logger.logerCount after calling Logger.createInstance(-1) ?
why the output is 1 not zero??


It would help if you explain why it should be zero.

BTW, it would also help if you properly indent your code too.

Henry
 
Mo Jay
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the following class, what is the value of Logger.logerCount after calling Logger.createInstance(-1) ?
why the output is 1 not zero??


I don't see how this program will print 1 or even zero, you are calling the method with -1 as an argument which is an exception according to your code. More over you didn't handle or catch the exception, and by the way if you can just put a System.out.println(loggerCount++) in your finally block then you would see that the value of loggerCount++ is zero indeed and not 1.

 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this related to SCJP ?

It appears you are trying to create a singleton which is not a SCJP concept. Let us know why you think the output should be what it is not
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic