-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingleGC.java
More file actions
60 lines (42 loc) · 1.25 KB
/
SingleGC.java
File metadata and controls
60 lines (42 loc) · 1.25 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class SingleGC{
public static void main(String A[]){
System.out.println("Inside main");
Derived dobj = new Derived();
System.out.println(dobj.i);
System.out.println(dobj.j);
System.out.println(dobj.x);
dobj.fun();
dobj.gun();
dobj = null;
System.gc();
System.out.println("End of main");
}
}
class Base {
public int i;
public int j;
public Base(){
System.out.println(" Inside Base Constructor");
this.i = 0; // here, use of 'this' is optional
this.j = 0;
}
protected void finalize(){
System.out.println(" Inside finalize method of Base");
}
public void fun(){
System.out.println("Inside Base fun");
}
}
class Derived extends Base{
public int x;
public Derived(){
System.out.println(" Inside Derived Constructor");
this.x = 0; // use of this is optional
}
protected void finalize(){
System.out.println(" Inside finalize method of Derived");
}
public void gun(){
System.out.println("Inside Derived gun");
}
}