-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritanceExample.java
More file actions
46 lines (31 loc) · 1007 Bytes
/
InheritanceExample.java
File metadata and controls
46 lines (31 loc) · 1007 Bytes
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
class Employee {
String name;
double salary;
public Employee(String name, double salary) {
this.name = name;
this.salary = salary;
}
public void displayInfo() {
System.out.println("Name: " + name);
System.out.println("Salary: " + salary);
}
}
class Manager extends Employee {
String department;
public Manager(String name, double salary, String department) {
super(name, salary); // Call superclass constructor
this.department = department;
}
@Override
public void displayInfo() {
super.displayInfo(); // Call superclass method
System.out.println("Department: " + department);
}
}
public class InheritanceExample {
public static void main(String[] args) {
Manager mgr = new Manager("Shrujan S", 85000.0, "Software Development");
System.out.println("Manager Details:");
mgr.displayInfo();
}
}