forked from VimalKrishnaRao/OOP-in-Java-Lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
4EmployeeInheritance.java
65 lines (58 loc) · 1.7 KB
/
4EmployeeInheritance.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
class Employee
{
String name;
int age;
long phoneNumber;
String address;
double salary;
void printSalary()
{
System.out.println("Salary: " + salary);
}
}
class Officer extends Employee
{
String specialization;
}
class Manager extends Employee
{
String department;
}
public class Main
{
public static void main(String[] args)
{
// Create an Officer object
Officer officer = new Officer();
officer.name = "Sarthak Bhatnagar";
officer.age = 35;
officer.phoneNumber = 1234567890;
officer.address = "123 Main Street";
officer.salary = 40000.0;
officer.specialization = "Human Resources";
// Print the officer's information
System.out.println("Officer Information:");
System.out.println("Name: " + officer.name);
System.out.println("Age: " + officer.age);
System.out.println("Phone Number: " + officer.phoneNumber);
System.out.println("Address: " + officer.address);
officer.printSalary();
System.out.println("Specialization: " + officer.specialization);
// Create a Manager object
Manager manager = new Manager();
manager.name = "Kaynath Sayaani";
manager.age = 40;
manager.phoneNumber = 9876543210;
manager.address = "456 Market Street";
manager.salary = 50000.0;
manager.department = "Sales";
// Print the manager's information
System.out.println("\nManager Information:");
System.out.println("Name: " + manager.name);
System.out.println("Age: " + manager.age);
System.out.println("Phone Number: " + manager.phoneNumber);
System.out.println("Address: " + manager.address);
manager.printSalary();
System.out.println("Department: " + manager.department);
}
}