0% found this document useful (0 votes)
9 views2 pages

Program 11

The document defines an abstract class 'Employee' with subclasses 'PermanentEmployee' and 'ContractEmployee' that implement salary calculation methods. It also includes a 'Calculator' class demonstrating method overloading for summing integers. The main method creates instances of these classes and displays their calculated salaries and totals.

Uploaded by

v6jnhhy8d8
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Program 11

The document defines an abstract class 'Employee' with subclasses 'PermanentEmployee' and 'ContractEmployee' that implement salary calculation methods. It also includes a 'Calculator' class demonstrating method overloading for summing integers. The main method creates instances of these classes and displays their calculated salaries and totals.

Uploaded by

v6jnhhy8d8
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program-11

// Abstract Class: Employee


abstract class Employee {
private int empNo;
private String empName;
private int empBasic;

// Parameterized constructor
public Employee(int empNo, String empName, int empBasic) {
[Link] = empNo;
[Link] = empName;
[Link] = empBasic;
}

// Getter methods
public int getEmpNo() {
return empNo;
}

public String getEmpName() {


return empName;
}

public int getEmpBasic() {


return empBasic;
}

// Abstract method to calculate salary


abstract public int calculateSalary();
}

// PermanentEmployee class extends Employee (Method Overriding)


class PermanentEmployee extends Employee {
private int hra;
private int da;

// Parameterized constructor
public PermanentEmployee(int empNo, String empName, int empBasic, int hra, int da) {
super(empNo, empName, empBasic);
[Link] = hra;
[Link] = da;
}

// Method Overriding: calculateSalary()


@Override
public int calculateSalary() {
return getEmpBasic() + hra + da;
}
}
// ContractEmployee class extends Employee (Method Overriding)
class ContractEmployee extends Employee {
private int contractAmount;

// Parameterized constructor
public ContractEmployee(int empNo, String empName, int empBasic, int contractAmount) {
super(empNo, empName, empBasic);
[Link] = contractAmount;
}

// Method Overriding: calculateSalary()


@Override
public int calculateSalary() {
return contractAmount;
}
}

// Calculator class with method overloading


class Calculator {
// Method Overloading: calculateTotal()
public int calculateTotal(int a, int b) {
return a + b;
}

// Method Overloading: calculateTotal()


public int calculateTotal(int a, int b, int c) {
return a + b + c;
}
}

public class Main {


public static void main(String[] args) {
// Create PermanentEmployee object
PermanentEmployee pe = new PermanentEmployee(1, "John Doe", 50000, 10000, 5000);
[Link]("Permanent Employee Salary: " + [Link]());

// Create ContractEmployee object


ContractEmployee ce = new ContractEmployee(2, "Jane Doe", 40000, 60000);
[Link]("Contract Employee Salary: " + [Link]());

// Create Calculator object and test method overloading


Calculator calculator = new Calculator();
[Link]("Total (2 numbers): " + [Link](10, 20));
[Link]("Total (3 numbers): " + [Link](10, 20, 30));
}
}

You might also like