-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInheritance.java
74 lines (71 loc) · 1.94 KB
/
Inheritance.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
import java.util.*;
class Employee{
String name,age,phno,address;
float salary;
Scanner sc=new Scanner(System.in);
Employee(){
System.out.println("Enter name:");
name=sc.nextLine();
System.out.println("Enter age:");
age=sc.nextLine();
System.out.println("Phno:");
phno=sc.nextLine();
System.out.println("Enter address:");
address=sc.nextLine();
System.out.println("Enter salary:");
salary=sc.nextFloat();
}
void printSalary(){
System.out.println("Salary is"+salary);
}
}
class Officer extends Employee{
String spec;
Officer(){
System.out.println("Enter specialisation:");
sc.nextLine();
spec=sc.nextLine();
}
void printSpec(){
System.out.println("Specialisation is"+spec);
}
void printAll(){
System.out.println("**OFFICER DETAILS**");
System.out.println("Name:"+name);
System.out.println("Age:"+age);
System.out.println("Phno:"+phno);
System.out.println("Address:"+address);
printSalary();
printSpec();
}
}
class Manager extends Employee{
String dept;
Manager(){
System.out.println("Enter department:");
sc.nextLine();
dept=sc.nextLine();
}
void printDept(){
System.out.println("Department is"+dept);
}
void printAll(){
System.out.println("**MANAGER DETAILS**");
System.out.println("Name:"+name);
System.out.println("Age:"+age);
System.out.println("Phno:"+phno);
System.out.println("Address:"+address);
printSalary();
printDept();
}
}
public class Inheritance {
public static void main(String[] args) {
System.out.println("ENTER MANAGER DETAILS");
Manager m=new Manager();
System.out.println("ENTER OFFICER DETAILS");
Officer o=new Officer();
m.printAll();
o.printAll();
}
}