-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinheritance.java
More file actions
81 lines (76 loc) · 2.23 KB
/
inheritance.java
File metadata and controls
81 lines (76 loc) · 2.23 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
import java.util.Scanner;
class Employee
{
public String name;
public int age;
public long phoneNumber;
public String address;
public double salary;
public void printSalary()
{
System.out.println("Salary="+salary);
}
}
class Officer extends Employee
{
public String specialization;
}
class Manager extends Employee
{
public String department;
}
class Empinheritance
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
Officer o = new Officer();
System.out.print("Enter the officer's name:");
o.name=sc.nextLine();
System.out.print("Enter Address:");
o.address=sc.nextLine();
System.out.print("Enter Specialization:");
o.specialization=sc.nextLine();
System.out.print("Enter Age:");
o.age=sc.nextInt();
System.out.print("Enter PhoneNumber:");
o.phoneNumber=sc.nextLong();
System.out.print("Enter Salary:");
o.salary=sc.nextDouble();
//sc.nextLine(); // to skip new Line
System.out.println("*********");
System.out.println("OFFICER DETAILS:");
System.out.println("Officer's name:"+o.name);
System.out.println("Address:"+o.address);
System.out.println("Specialization:"+o.specialization);
System.out.println("Age:"+o.age);
System.out.println("PhoneNumber:"+o.phoneNumber);
o.printSalary();
System.out.println("*********");
sc.nextLine(); // to skip new Line
Manager m = new Manager();
System.out.println("Enter the manager's Detail");
System.out.print("Enter the manager's name:");
m.name=sc.nextLine();
System.out.print("Enter Address:");
m.address=sc.nextLine();
System.out.print("Enter Department:");
m.department=sc.nextLine();
System.out.print("Enter Age:");
m.age=sc.nextInt();
System.out.print("Enter PhoneNumber:");
m.phoneNumber=sc.nextLong();
System.out.print("Enter Salary:");
m.salary=sc.nextDouble();
sc.nextLine(); // to skip new Line
System.out.println("*********");
System.out.println("OFFICER DETAILS:");
System.out.println("Officer's name:"+m.name);
System.out.println("Age:"+m.age);
System.out.println("Address:"+m.address);
System.out.println("PhoneNumber:"+m.phoneNumber);
System.out.println("Department:"+m.department);
m.printSalary();
System.out.println("*********");
}
}