• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what is the ouptut of this code??

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I am not a spy. Definitely. Definitely not a spy. Not me. No way. But this tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic