This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Fix an infity loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Fix an infity loop" Watch "Fix an infity loop" New topic

Fix an infity loop

Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86


I need to create 20 objects of Class B, using while loop in class A. In class B i have a variable that should increment each time an object is created, how i should build class B's cunstractor so each time that variable increase and not become zero?
Pavan Kumar Dittakavi
Ranch Hand

Joined: Feb 12, 2011
Posts: 104

Use a static variable!
Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Thank you
I agree. Here's the link:
subject: Fix an infity loop
Similar Threads
While Loop Mystery...
volatile variables doubt
declaring variables
Variable declaration
a final variable declared in a while loop