Skip to content

Commit 0bee9b7

Browse files
committed
Coded garbage.java
1 parent e4c7333 commit 0bee9b7

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

Diff for: Java_Exp_4/Garbage.java

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import java.util.Scanner;
2+
public class Garbage{
3+
4+
public static void main(String args[]) {
5+
6+
Student obj=new Student();
7+
obj.getDetails();
8+
obj.showDetails();
9+
obj=null;
10+
System.gc();
11+
12+
}
13+
}
14+
15+
class Student {
16+
Scanner sc = new Scanner(System.in);
17+
18+
String name,number;
19+
int rollno;
20+
21+
void getDetails() {
22+
System.out.printf("Enter the Name of Student : ");
23+
name = sc.next();
24+
System.out.printf("Enter the Roll No : ");
25+
rollno = sc.nextInt();
26+
System.out.printf("Enter Phone Number : ");
27+
number = sc.next();
28+
29+
}
30+
31+
void showDetails() {
32+
System.out.printf("\nThe Name of Student is %s \n",name);
33+
System.out.printf("Enter the Roll No : %d \n",rollno);
34+
System.out.printf("Enter Phone Number : %s \n",number);
35+
}
36+
37+
protected void finalize() {
38+
System.out.println("\nGarbage of Object Collected");
39+
}
40+
}

Diff for: Java_Exp_4/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@ Triangle has 3 sides.
5959
Hexagon has 6 sides.
6060
```
6161

62+
[Garbage.java](https://github.com/akkupy/JavaS3/blob/master/Java_Exp_4/Garbage.java) - Write a Java program to demonstrate the use of garbage collector.
63+
64+
```
65+
Enter the Name of Student : Akash
66+
Enter the Roll No : 12
67+
Enter Phone Number : 1231234
68+
69+
The Name of Student is Akash
70+
Enter the Roll No : 12
71+
Enter Phone Number : 1231234
72+
73+
Garbage of Object Collected
74+
```
75+
76+
6277
[engineer_employee.java](https://github.com/akkupy/JavaS3/blob/master/Java_Exp_4/engineer_employee.java) - Write two Java classes Employee and Engineer. Engineer should inherit from Employee class. Employee class to have two methods display() and calcSalary(). Write a program to display the engineer salary and to display from Employee class using a single object instantiation (i.e., only one object creation is allowed).
6378

6479
a. display() only prints the name of the class and does not return any value. Ex. “Name of class is Employee.”

0 commit comments

Comments
 (0)