Create an interface called EmployeeInterface. This interface has the following abstract method:
public void workingOn(String task);
The Employee class implements this interface, and provides an implementation for workingOn() which displays that the employee is working on a certain task.
(Note what happens if you don’t implement workingOn().)
interface EmployeeInterface {
void workingOn(String task);
}
class Employee implements EmployeeInterface {
// If `workingOn` method is not implemented, then a compilation error happens
public void workingOn(String task) {
System.out.println("The employee is working on " + task);
}
}
class Test {
public static void main(String[] args) {
Employee employee = new Employee();
employee.workingOn("coding");
}
}
Comments
Leave a comment