-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6_garbageCollection.java
47 lines (43 loc) · 1.1 KB
/
6_garbageCollection.java
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
6. Write a Java program to demonstrate garbage collection.
*/
import java.util.Scanner;
class employee {
private int ID;
private String name;
private int age;
private static int nextId = 1;
public employee(String name, int age) {
this.name = name;
this.age = age;
this.ID = nextId++;
}
public void eshow() {
System.out.println("ID=" + ID + "\nName=" + name + "\nAge=" + age);
}
public void showNextId() {
System.out.println("Next employee ID will be=" + nextId);
}
}
class garbageCollection {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String e, f, g;
System.out.println("Enter the name of the 1st employee: ");
e = sc.next();
System.out.println("Enter the name of the 2nd employee: ");
f = sc.next();
System.out.println("Enter the name of the 3rd employee: ");
g = sc.next();
employee E = new employee(e, 10);
employee F = new employee(f, 11);
employee G = new employee(g, 12);
E.eshow();
E.showNextId();
F.eshow();
F.showNextId();
G.eshow();
G.showNextId();
sc.close();
}
}