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
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