-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployeeInheritence.java
More file actions
76 lines (65 loc) · 2.14 KB
/
EmployeeInheritence.java
File metadata and controls
76 lines (65 loc) · 2.14 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
//Program to create a class named 'Member' having the following members: Name, Age, Phone number, Address, Salary. It also has a method named printSalary which prints the salary of the members. Two classes Employee and Manager inherits the Member class. The Employee and Manager' classes have data members specialization and department respectively. Now, assign name, age, phone number, address and salary to an employee and a manager by making an object of both of these classes and print the same.
class Member
{
String name;
int age;
long ph_num;
String address;
double salary;
Member(String n,int a,long p,String ad,double s) // Constructor
{
this.name=n;
this.age=a;
this.ph_num=p;
this.address=ad;
this.salary=s;
}
void print_details()
{
System.out.print("\nEmployee Details are as:");
System.out.print("\nName: " + name);
System.out.print("\nAge: " + age);
System.out.print("\nAddress: " + address);
System.out.print("\nPhone number: " + ph_num);
}
void print_Salary()
{
System.out.print("\nSalary: " + this.salary);
}
}
class Employee extends Member
{
String specialization="Market Research";
String department="Marketing and Sales";
Employee() //Constructor
{
super("Pramod",24,9876767876l,"XYZ",95140.5); //Calling Constructor of Parent Class
}
}
class Manager extends Member
{
String specialization="Market Research";
String department="Marketing and Sales";
Manager() // Consructor
{
super("Revanth",25,9876447876l,"ABC",96140.5); //Calling Constructor of Parent Class
}
}
class EmployeeInheritence
{
public static void main(String args[])
{
Employee e = new Employee();
Manager m = new Manager();
System.out.print("\n----Employee details----\n");
e.print_details();
System.out.print("\nSpecialization: "+e.specialization);
System.out.print("\nDepartment: "+e.department);
e.print_Salary();
System.out.print("\n----Manager details----\n");
m.print_details();
System.out.print("\nSpecialization: "+m.specialization);
System.out.print("\nDepartment: "+m.department);
m.print_Salary();
}
}