Forums Register Login

what is the ouptut of this code??

+Pie Number of slices to send: Send


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
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
 

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.

+Pie Number of slices to send: Send
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
Climb the rope! CLIMB THE ROPE! You too tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 704 times.
Similar Threads
Accessing method of one application from another
a parameterised constructor that is not returning an object
final instance variable
Canadian Post Codes as Base 26 calculations
Static object doesn't get collected. Why?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:09:43.