-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSingle_inheritance.java
More file actions
50 lines (50 loc) · 1.02 KB
/
Copy pathSingle_inheritance.java
File metadata and controls
50 lines (50 loc) · 1.02 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
import java.util.Scanner;
class Employee
{
int basic_sal,da,ta,salary;
void calcsalary()
{
salary=basic_sal+da+ta;
System.out.println("Salary of employee is: "+salary);
}
void display()
{
System.out.println("Name of the class is Employee");
}
}
class Engineer extends Employee
{
Engineer(int s, int d, int t)
{
basic_sal=s;
da=d;
ta=t;
}
void calcsalary()
{
super.calcsalary();
System.out.println("Salary of Engineer is: "+(2*salary));
}
void display()
{
super.display();
System.out.println("Name of the class is Engineer");
}
}
public class Single_inheritance
{
public static void main(String args[])
{
int basic,da,ta;
Scanner in = new Scanner(System.in);
System.out.print("Enter basic salary: ");
basic = in.nextInt();
System.out.print("Enter dearence allowance: ");
da = in.nextInt();
System.out.print("Enter travel allowance: ");
ta = in.nextInt();
Engineer ob = new Engineer(basic,da,ta);
ob.calcsalary();
ob.display();
}
}