-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHInheritance.java
More file actions
101 lines (101 loc) · 3.04 KB
/
Copy pathHInheritance.java
File metadata and controls
101 lines (101 loc) · 3.04 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
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
97
98
99
100
101
import java.util.Scanner;
class Employee
{
String name;
int age;
long phonenumber;
String address;
float salary;
Employee(String name1,int age1,long phonenumber1,String address1,float salary1)
{
name=name1;
age=age1;
phonenumber=phonenumber1;
address=address1;
salary=salary1;
}
void printEmployee()
{
System.out.println("Name: "+name);
System.out.println("Age: "+age);
System.out.println("Phonenumber: "+phonenumber);
System.out.println("Address: "+address);
}
void printSalary()
{
System.out.println("Salary: "+salary);
}
}
class Officer extends Employee
{
String specialization;
Officer(String name1,int age1,long phonenumber1,String address1,float salary1,String specialization1)
{
super(name1,age1,phonenumber1,address1,salary1);
specialization=specialization1;
}
void printSpecialization()
{
System.out.println("Specialization= "+specialization);
}
}
class Manager extends Employee
{
String department;
Manager(String name1,int age1,long phonenumber1,String address1,float salary1,String department1)
{
super(name1,age1,phonenumber1,address1,salary1);
department=department1;
}
void printDepartment()
{
System.out.println("Depertment= "+department);
}
}
public class HierarchialInheritance
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int age;
String name,address,specialization,department;
float salary;
long phonenumber;
System.out.println("Enter the details of the officer");
System.out.println("Enter name:");
name=sc.next();
System.out.println("Enter Age:");
age=sc.nextInt();
System.out.println("Enter phonenumber:");
phonenumber=sc.nextLong();
System.out.println("Enter address:");
address=sc.next();
System.out.println("Enter salary:");
salary=sc.nextFloat();
System.out.println("Enter specialization:");
specialization=sc.next();
Officer o=new Officer(name,age,phonenumber,address,salary,specialization);
System.out.println("Enter the details of the Manager");
System.out.println("Enter name:");
name=sc.next();
System.out.println("Enter Age:");
age=sc.nextInt();
System.out.println("Enter phonenumber:");
phonenumber=sc.nextLong();
System.out.println("Enter address:");
address=sc.next();
System.out.println("Enter salary:");
salary=sc.nextFloat();
System.out.println("Enter department:");
department=sc.next();
Manager m=new Manager(name,age,phonenumber,address,salary,department);
System.out.println("DETAILS OF OFFICER");
o.printEmployee();
o.printSalary();
o.printSpecialization();
System.out.println("DETAILS OF MANAGER");
m.printEmployee();
m.printSalary();
m.printDepartment();
}
}