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 what is the ouptut of this code?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what is the ouptut of this code??" Watch "what is the ouptut of this code??" New topic
Author

what is the ouptut of this code??

Heba Mahmoud
Ranch Hand

Joined: Apr 26, 2009
Posts: 62


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


SCJP Pass 85%....
Thousands of candles can be lighted from a single candle, and the life of the candle will not be shortened
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18840
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Mo Jay
Ranch Hand

Joined: Feb 16, 2009
Posts: 83
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

Joined: Feb 24, 2006
Posts: 6661
    
    5

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


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is the ouptut of this code??