-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinalize.java
38 lines (36 loc) · 1.17 KB
/
Finalize.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
import java.lang.*;
class Laptop {
String brand, model;
int ram, storage;
boolean isCameraAvailable;
public Laptop(String brand, String model,int ram, int storage, boolean isCameraAvailable) {
this.brand = brand;
this.model = model;
this.ram = ram;
this.storage = storage;
this.isCameraAvailable = isCameraAvailable;
}
public void printSpecs() {
System.out.println("\nSpecs of " + brand + " " + model);
System.out.println("Ram: " + ram + "\nStorage: " + storage);
if(isCameraAvailable)
System.out.println("Camera Available\n");
else
System.out.println("No Camera\n");
}
@Override
protected void finalize() throws Throwable {
super.finalize();
System.out.println("Finalized " + this);
}
}
public class Finalize {
public static void main(String[] args) throws Throwable {
Laptop l1 = new Laptop("Hp", "Pavillion", 8, 512, true);
Laptop l2 = new Laptop("Lenovo", "IdeaPad", 4, 256, false);
l1.printSpecs();
l2.printSpecs();
System.gc();
l1.printSpecs();
}
}