-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance.java
More file actions
86 lines (84 loc) · 1.88 KB
/
inheritance.java
File metadata and controls
86 lines (84 loc) · 1.88 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
import java.util.*;
class employee{
int a,s;
String n;
String m;
long p;
Scanner sc=new Scanner (System.in);
void read()
{
System.out.println("enter the name");
n=sc.nextLine();
System.out.println("enter employee age");
a=sc.nextInt();
System.out.println("enter address");
m=sc.next();
System.out.println("enter phone number");
p=sc.nextLong();
}
void printsalary()
{
System.out.println("enter the salary");
s=sc.nextInt();
System.out.println();
}
void dispalay()
{
System.out.println("NAME: "+n);
System.out.println("AGE: "+a);
System.out.println("ADDRESS: "+m);
System.out.println("PHONE: "+p);
System.out.println("SALARY: "+s);
}
}
class officer extends employee
{
String sp;
void sread()
{
Scanner sc= new Scanner(System.in);
super.read();
System.out.println("Area of specialization");
sp=sc.nextLine();
}
void sprint()
{
super.dispalay();
System.out.println("SPECIALIZATION: "+sp);
System.out.println();
}
}
class manager extends employee
{
String dp;
void sread()
{
Scanner sc =new Scanner(System.in);
super.read();
System.out.println("enter the department");
dp=sc.nextLine();
}
void sprint()
{
super.dispalay();
System.out.println("DEPARTMENT: "+dp);
System.out.println();
}
}
class inheritance
{
public static void main(String[] args) {
officer o=new officer();
manager m=new manager();
System.out.println("officer:");
o.sread();
o.printsalary();
System.out.println("Manager");
m.sread();
m.printsalary();
System.out.println("officer:");
o.sprint();
System.out.println("manager:");
m.sprint();
}
}