class Employee {
private String last;
private String first;
private String title;
private int age;
static int count = 2;
public Employee() {++count;}
public Employee(String last, String first,
String title, int age)
{
this.last = last;
this.first = first;
this.title = title;
this.age = age;
}
public String getLast() {
return last;
}
public String getFirst() {
return first;
}
public String getTitle() {
return title;
}
public int getAge() {
return age;
}
public void setLast(String last) {
this.last = last;
}
public void setFirst(String first) {
this.first = first;
}
public void setTitle(String title) {
this.title = title;
}
public void setAge(int age) {
this.age = age;
}
public String toString() {
return "{" + last + "," + first +
"," + title+ "," + age + "}";
}
public static int getCount() {
return count;
}
protected void finalize() {
count--;
}
}
public class Trial {
public static void main(String[] args)
{
Employee e0 = new Employee();
Employee e = new Employee("Malone", "Karl", "Forward", 36);
System.out.println(e);
System.out.println("Employee.count == " + Employee.getCount());
e0 = null;
System.gc();
System.out.println("Employee.count == " + Employee.getCount());
e = null;
System.gc();
System.out.println("Employee.count == " + Employee.getCount());
}
}
(java 6)
when i run it the nb of object doesnt change
finalize()doesnt affect static attribute???
why??