interface
keywordpublic abstract
public static final
public interface IMyQueue {
void enqueue(Object o);
Object dequeue();
Object peek();
int size();
}
public class WaitingList implements IMyQueue {
public void enqueue(Object o) {
//code here
}
public Object dequeue() {
//code here
}
public Object peek() {
//code here
}
public int size() {
//code here
}
}
IMyQueue wait = new WaitingList();
wait.enqueue(new Person());
wait.dequeue();
We can call any methods
defined by the interface
public
and protected
attributes and methods of superclasssuper()
constructorpublic class Canine {
protected name;
public void bark() {
//code here
}
}
public class Dog extends Canine {
protected owner;
public void pet() {
//code here
}
}
public class GuideDog extends Dog {
protected trainer;
public void guide() {
//code here
}
}
GuideDog lassie = new GuideDog();
lassie.bark();
lassie.pet();
lassie.guide();
Classes in Java can only
directly inherit from one superclass
Classes may implement
any number of interfaces