You are on page 1of 2

In Java multiple inheritance is not supported.

Instead, a technique called


as delegation, which is based on the use of interfaces, can be used:

interface Student {
public float getGPA();
}

interface Employee {
public float getSalary();
}

public class StudentImpl implements Student {


public float getGPA() {
// make the calculations
}
protected float gpa;
...
}

public class EmployeeImpl implements Employee {


public float getSalary() {
// calculate the salary
}
protected float salary;
...
}

public class FullTimeStudent extends StudentImpl {


// method getGPA and field gpa are inherited.
// there may be other methods and fields.
}

public class FullTimeEmployee extends StudentImpl {


// method getSalary and field salary are inherited.
// there may be other methods and fields.
}

public class StudentEmployee implements Student, Employee {


public StudentEmployee() {
studentImpl=new StudentImpl();
employeeImpl=new EmployeeImpl();
...
}
public float getGPA() {
return studentImpl.getGPA();
}

public float getSalary() {


return employeeImpl.getSalary();
}

protected StudentImpl studentImpl;


protected EmployeeImpl employeeImpl;
...
...
}

You might also like