Follow these steps to implement the example:
- Create a class named MyPriorityTask that implements the Runnable and Comparable interfaces parameterized by the MyPriorityTask class interface:
public class MyPriorityTask implements Runnable, Comparable<MyPriorityTask> {
- Declare a private int attribute named priority:
private int priority;
- Declare a private String attribute called name:
private String name;
- Implement the constructor of the class to initialize its attributes:
public MyPriorityTask(String name, int priority) { this.name=name; this.priority=priority; }
- Implement a method to return the value of the priority attribute:
public int getPriority(){ return priority; }
- Implement the compareTo()