-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.java
More file actions
30 lines (24 loc) · 816 Bytes
/
Copy pathExample.java
File metadata and controls
30 lines (24 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package object2;
class Example {
private static int createdCount = 0; // Tracks the number of objects created
private static int destroyedCount = 0; // Tracks the number of objects finalized
private int x;
Example() {
x = 10;
createdCount++; // Increment the creation count
System.out.println("Ex constructor " + this);
}
@Override
protected void finalize() {
destroyedCount++; // Increment the destruction count
System.out.println("In finalize: " + this);
}
// Static method to get the number of objects created
public static int getCreatedCount() {
return createdCount;
}
// Static method to get the number of objects finalized
public static int getDestroyedCount() {
return destroyedCount;
}
}