Interfaces
Defining an interface
Java Syntax
public interface InterfaceName {
method prototypes
}
Example
public interface Ownable {
Owner owner();
boolean updateOwner(Owner newOwner);
}
Implementing an interface
Java Syntax
public class ClassName implements InterfaceName1, InterfaceName2, ... {
data members
constructors
methods
}
Example
public class Car implements Ownable {
// data members
private Owner myOwner;
// constructors
// other Car methods
public Owner owner() {
return myOwner; // method implementation
}
public void updateOwner(Owner newOwner) {
myOwner = newOwner;
return true;
}
}