-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMethodOverriding.java
57 lines (45 loc) · 1.46 KB
/
MethodOverriding.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
import java.util.Scanner;
class Employee1 {
double salary, DA, HRA, salary1;
Employee1(double salary, double DA, double HRA) {
this.salary = salary;
this.DA = DA;
this.HRA = HRA;
}
void display() {
System.out.println("======== Employee ========");
}
void calcSalary() {
salary1 = salary + salary * (DA / 100) + salary * (HRA / 100);
System.out.println("Gross saalary of the Employee = " + salary1);
}
}
class Engineer extends Employee1 {
Engineer(double salary, double DA, double HRA) {
super(salary, DA, HRA);
}
void display() {
super.display();
super.calcSalary();
System.out.println("======== Engineer ========");
}
void calcSalary() {
System.out.println("Gross saalary of the Engineer = " + salary1 * 2);
}
}
public class MethodOveriding {
public static void main(String[] args) {
double salary, DA, HRA;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the basic salary of the Employee: ");
salary = sc.nextDouble();
System.out.print("Enter DA% of Employee: ");
DA = sc.nextDouble();
System.out.print("Enter HRA% of Employee: ");
HRA = sc.nextDouble();
Engineer Eng = new Engineer(salary, DA, HRA);
Eng.display();
Eng.calcSalary();
sc.close();
}
}