forked from VimalKrishnaRao/OOP-in-Java-Lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4EmployeeEngineer.java
48 lines (41 loc) · 1.02 KB
/
4EmployeeEngineer.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
public class Employee
{
private String name;
private int salary;
public Employee(String name)
{
this.name = name;
this.salary = 10000;
}
public void display()
{
System.out.println("Name of class is Employee.");
}
public void calcSalary()
{
System.out.println("Salary of employee is " + salary);
}
}
public class Engineer extends Employee
{
public Engineer(String name)
{
super(name);
}
@Override
public void calcSalary()
{
System.out.println("Salary of employee is 20000");
}
}
public class Main
{
public static void main(String args[])
{
Employee employee = new Engineer("Vimal");
employee.display();
employee.calcSalary();
}
}
//In this example, I assumed that you wanted the Engineer class to override the calcSalary() method of the Employee class.
//If you want the Engineer class to simply inherit the calcSalary() method from the Employee class, you can remove the override annotation and the implementation of calcSalary() in the Engineer class.