-
Notifications
You must be signed in to change notification settings - Fork 0
/
Abstract Classes and overriding.java
58 lines (41 loc) · 1.17 KB
/
Abstract Classes and overriding.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.io.*;
abstract class Employee{
String name;
int id;
int base; //base Salary
Employee(int id, String name, int base){
this.id = id;
this.name = name;
this.base = base;
}
abstract public int calculateSalary();
//abstract public void displayInfo();
}
class Manager extends Employee{
int juniorEMployees;
Manager(int id, String name, int base, int juniorEMployees){
super(id, name, base);
this.juniorEMployees = juniorEMployees;
}
public int calculateSalary(){
return this.base + juniorEMployees*10;
}
}
class programmer extends Employee{
int overtime;
programmer(int id, String name, int base, int overtime){
super(id, name, base);
this.overtime = overtime;
}
public int calculateSalary(){
return this.base + overtime*15;
}
}
class GFG {
public static void main (String[] args) {
programmer p1 = new programmer(1,"Deep Singh", 1000, 15);
System.out.println(p1.calculateSalary());
Manager m1 = new Manager(2,"Pratik Rout", 2000, 5);
System.out.println(m1.calculateSalary());
}
}