-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExp72.java
More file actions
63 lines (51 loc) · 1.46 KB
/
Exp72.java
File metadata and controls
63 lines (51 loc) · 1.46 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
61
62
63
abstract class Employee {
String name;
String role;
Employee(String name, String role) {
this.name = name;
this.role = role;
}
abstract double calculateSalary();
abstract void displayDetails();
}
class Manager extends Employee {
double fixedSalary;
Manager(String name, double fixedSalary) {
super(name, "Manager");
this.fixedSalary = fixedSalary;
}
double calculateSalary() {
return fixedSalary;
}
void displayDetails() {
System.out.println("Name: " + name);
System.out.println("Role: " + role);
System.out.println("Salary: ₹" + calculateSalary());
}
}
class Developer extends Employee {
double hourlyRate;
int hoursWorked;
Developer(String name, double hourlyRate, int hoursWorked) {
super(name, "Developer");
this.hourlyRate = hourlyRate;
this.hoursWorked = hoursWorked;
}
double calculateSalary() {
return hourlyRate * hoursWorked;
}
void displayDetails() {
System.out.println("Name: " + name);
System.out.println("Role: " + role);
System.out.println("Salary: ₹" + calculateSalary());
}
}
public class Exp72 {
public static void main(String[] args) {
Employee m = new Manager("Ravi Sharma", 80000);
Employee d = new Developer("Anjali Mehta", 500, 160);
m.displayDetails();
System.out.println();
d.displayDetails();
}
}