This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

wats the problem in creating mutiple instance for class in this code  RSS feed

 
krishna balaji
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this code both object a and b are not created and its giving unexpected output
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by krishna balaji:
...In this code both object a and b are not created and its giving unexpected output

How are you getting output if neither object is created?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One likely cause of your troubles is that the member "m" in confserver is static, but it's assigned in the constructor. That means each time you create a confserver, any previous value of m is lost, and all confserver objects share the latest one.

If I may: Java programmers universally use capital letters to name classes; for example "ConfServer". Using all-lowercase class names makes your code exceedingly hard to read for an an experienced programmer.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!