-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHierarchicalInheritance.java
96 lines (72 loc) · 2.61 KB
/
HierarchicalInheritance.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import java.util.Scanner;
class Employee {
String name;
int age;
String phoneNumber;
String address;
double salary;
Employee(String name, int age, String phoneNumber, String address, double salary) {
this.name = name;
this.age = age;
this.phoneNumber = phoneNumber;
this.address = address;
this.salary = salary;
}
void printSalary() {
System.out.println("Salary: " + salary);
}
}
class Officer extends Employee {
String specialization;
Officer(String name, int age, String phoneNumber, String address, double salary, String specialization) {
super(name, age, phoneNumber, address, salary);
this.specialization = specialization;
}
void displayOfficerDetails() {
System.out.println("Officer Name: " + name);
System.out.println("Age: " + age);
System.out.println("Phone Number: " + phoneNumber);
System.out.println("Address: " + address);
printSalary();
System.out.println("Specialization: " + specialization);
}
}
class Manager extends Employee {
String department;
Manager(String name, int age, String phoneNumber, String address, double salary, String department) {
super(name, age, phoneNumber, address, salary);
this.department = department;
}
void displayManagerDetails() {
System.out.println("Manager Name: " + name);
System.out.println("Age: " + age);
System.out.println("Phone Number: " + phoneNumber);
System.out.println("Address: " + address);
printSalary();
System.out.println("Department: " + department);
}
}
public class HierarchicalInheritance {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Officer name");
String name = sc.nextLine();
System.out.println("Enter Officer age");
int age = sc.nextInt();
System.out.println("Enter Officer phoneNumber");
String phoneNumber = sc.nextLine();
System.out.println("Enter Officer address");
String address = sc.nextLine();
System.out.println("Enter Officer salary");
double salary = sc.nextDouble();
System.out.println("Enter Officer specialisation");
String specialisation = sc.nextLine();
Officer officer = new Officer(name, age, phoneNumber, address, salary, specialisation);
Manager manager = new Manager("Bob", 40, "987-654-3210", "456 Elm St", 80000, "Sales");
System.out.println("Officer Details:");
officer.displayOfficerDetails();
System.out.println();
System.out.println("Manager Details:");
manager.displayManagerDetails();
}
}