Skip to content

Commit 4fe4b2a

Browse files
committed
inheritance 4 done
1 parent a0d6e2a commit 4fe4b2a

File tree

8 files changed

+77
-0
lines changed

8 files changed

+77
-0
lines changed

Diff for: Inheritance/Employee.java

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package Inheritance;
2+
3+
public class Employee {
4+
5+
private int id;
6+
private String name;
7+
private double salary;
8+
9+
public Employee(int id, String name, double salary) {
10+
this.id = id;
11+
this.name = name;
12+
this.salary = salary;
13+
}
14+
15+
protected void work(){
16+
System.out.println("employee work");
17+
}
18+
19+
protected double getSalary(){
20+
return salary;
21+
}
22+
23+
@Override
24+
public String toString() {
25+
return "Employee{" +
26+
"id=" + id +
27+
", name='" + name + '\'' +
28+
", salary=" + salary +
29+
'}';
30+
}
31+
}

Diff for: Inheritance/HRManager.java

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package Inheritance;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class HRManager extends Employee{
7+
8+
private List<Employee> employeeList;
9+
private int workours;
10+
11+
public HRManager(int id, String name, double salary, int workHours) {
12+
super(id, name, salary);
13+
this.workours = workHours;
14+
this.employeeList = new ArrayList<Employee>();
15+
}
16+
17+
public int getWorkHours() {
18+
return workours;
19+
}
20+
21+
public List<Employee> addEmployee(Employee e) {
22+
employeeList.add(e);
23+
24+
return employeeList;
25+
}
26+
27+
@Override
28+
public String toString() {
29+
return "HRManager{" +
30+
"employeeList=" + employeeList +
31+
", workours=" + workours +
32+
'}';
33+
}
34+
}

Diff for: Inheritance/Main.java

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package Inheritance;
22

3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
37
public class Main {
48

59

@@ -14,6 +18,14 @@ public static void main(String[] args) {
1418
System.out.println(rectangle.getArea());
1519

1620

21+
22+
Employee employee = new HRManager(1, "Alamin", 10000, 8);
23+
System.out.println(employee.getSalary());
24+
employee.work();
25+
HRManager hr = new HRManager(2, "Alamin", 10000, 9);
26+
System.out.println(hr.getSalary());
27+
System.out.println(hr.getWorkHours());
28+
1729
}
1830

1931
}
490 Bytes
Binary file not shown.
796 Bytes
Binary file not shown.
466 Bytes
Binary file not shown.
338 Bytes
Binary file not shown.
499 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)