Upload files to "OOP/Java/Lab/Week7"
This commit is contained in:
parent
4091242dd9
commit
50fb2e24af
2 changed files with 67 additions and 0 deletions
28
OOP/Java/Lab/Week7/ObjectCountDemo.java
Normal file
28
OOP/Java/Lab/Week7/ObjectCountDemo.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
class ObjectCount {
|
||||
private static int count = 0;
|
||||
|
||||
public ObjectCount() {
|
||||
count++;
|
||||
}
|
||||
|
||||
public static int getCount() {
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
public class ObjectCountDemo {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Initial count: " + ObjectCount.getCount());
|
||||
|
||||
ObjectCount obj1 = new ObjectCount();
|
||||
System.out.println("Count after creating obj1: " + ObjectCount.getCount());
|
||||
|
||||
ObjectCount obj2 = new ObjectCount();
|
||||
System.out.println("Count after creating obj2: " + ObjectCount.getCount());
|
||||
|
||||
ObjectCount obj3 = new ObjectCount();
|
||||
System.out.println("Count after creating obj3: " + ObjectCount.getCount());
|
||||
|
||||
System.out.println("Final count: " + ObjectCount.getCount());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue