-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSingleInheritanceSuperKeyword.java
39 lines (28 loc) · 1.3 KB
/
SingleInheritanceSuperKeyword.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
// 31. Single Inheritance & Super Keyword
// Write two Java classes Employee and Engineer. The Engineer class should inherit from the Employee class. Employee class to have two methods display() and calcSalary(). Write a program to display the engineer salary and to display from Employee class using a single object instantiation (i.e., only one object creation is allowed).
// ● display() only prints the name of the class and does not return any value. Ex. “ Name of the class is Employee.”
// ● calcSalary() in Employee displays “Salary of employee is 10000” and calcSalary() in Engineer displays
// “Salary of an employee is 20000.”
class Employee {
void display() {
System.out.println("Name of the class is Employee.");
}
void calcSalary() {
System.out.println("Salary of employee is 10000.");
}
}
class Engineer extends Employee {
void calcSalary() {
System.out.println("The salary of employee is given below :");
super.calcSalary();
System.out.println("This is the salary of engineer : ");
System.out.println("Salary of an engineer is 20000.");
}
}
public class SingleInheritanceSuperKeyword {
public static void main(String[] args) {
Engineer engineer = new Engineer();
engineer.display();
engineer.calcSalary();
}
}