Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Same value in all objects

Status
Not open for further replies.

1510982

Programmer
Feb 17, 2002
57
0
0
SI
I've read somewhere that the variables that are static are have the same value for all objects created from same class. Is that true? How to count people then in the all instances of Class withouth some other class. Is this approach right? I don't know if I'm right, at first I wanted to make a Integer class, but I then found out (thanks to some other collegue at this forum) that the value cannot be incremented... So here it goes

public class Person {
public static int countPersons; //count all persons

public Person() {
incrementPerson();
}

private void incrementPerson() {
if (this.countPersons == 0) {
this.countPersons = 0;
} else {
this.countPersons++;
}
}
}

Thanks in advance.

Rastko
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top