Skip to content

Commit e4c7333

Browse files
committed
Coded exp 4 3rd prob
1 parent a40c5d8 commit e4c7333

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

Java_Exp_4/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,17 @@ Department IT
5757
Rectangle has 4 sides.
5858
Triangle has 3 sides.
5959
Hexagon has 6 sides.
60+
```
61+
62+
[engineer_employee.java](https://github.com/akkupy/JavaS3/blob/master/Java_Exp_4/engineer_employee.java) - Write two Java classes Employee and Engineer. Engineer should inherit from 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).
63+
64+
a. display() only prints the name of the class and does not return any value. Ex. “Name of class is Employee.”
65+
66+
b. calcSalary() in Employee displays “Salary of employee is 10000” and calcSalary() in Engineer displays “Salary of employee is 20000.”
67+
68+
69+
```
70+
Name of class is Employee.
71+
Salary of Employee is 10000
72+
Salary of Engineer is 20000
6073
```

Java_Exp_4/engineer_employee.java

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
class Employee
2+
{
3+
4+
void display()
5+
{
6+
7+
System.out.println("Name of class is Employee.");
8+
9+
}
10+
11+
void calcSalary()
12+
{
13+
14+
System.out.println("Salary of Employee is 10000");
15+
16+
}
17+
18+
}
19+
20+
class Engineer extends Employee
21+
{
22+
23+
void calcSalary()
24+
{
25+
super.calcSalary();
26+
System.out.println("Salary of Engineer is 20000");
27+
28+
}
29+
30+
}
31+
32+
public class engineer_employee {
33+
public static void main(String args[])
34+
{
35+
36+
Engineer eng = new Engineer();
37+
eng.display();
38+
eng.calcSalary();
39+
40+
}
41+
}

0 commit comments

Comments
 (0)