

abstract keyword identifies features intended for protocol
definition.
interface Candy {
public abstract int calorieCount();
Nuts [] containsNuts();
boolean hasFlavonoids();
}
interface 3DRectangle {
double height();
double width();
double length();
}
interface ChocolateBar
extends Candy {
ChocolateKind chocolateKind();
// and so on.
}
public interface ChocolateBar
extends Candy, 3DRectangle { ... }
class ThreeMusketeers
implements ChocolateBar
int calorieCount() { ... }
boolean hasFlavonoids { return true; }
// and so on
interface Universals {
public static final int
tearsCried = 96,
theAnswer = 42;
}
class Universals {
private Universals() { }
public static final int
tearsCried = 96,
theAnswer = 42;
}
interfaceComparableint compareTo(Object o); public interfaceDestroyablevoid destroy(); boolean isDestroyed(); public interfaceReadableint read(CharBuffercb);
class Card implementsComparableint compareTo(Object o) { ... } // and so on. class SecurityCertificate implementsDestroyable,Readablevoid destroy() { ... } boolean isDestroyed() { ... } int read(CharBuffer cb) { ... } // and so on.
boolean beats(Comparablex) { ... } void validate(Destroyabletag) { ... } Message read(Readableinput) { ... }
SecurityCertificate ticket = new SecurityCertificate() validate(ticket) Message m = read(ticket)

T copy()
cpy = new T()
for each v: this.instance-variable
cpy.v = v
return cpy
copy() implements a shallow copy.


T deepCopy()
cpy = new T()
for each v: this.instance-variable
cpy.v = v.deepCopy()
return cpy
Blob cpy = ci.deepCopy()

Object.clone()protectedObjectclone()
implements copying.
$ cat t.java
class blob { }
class t {
public static void main(String args[]) {
blob b = new blob();
blob cpy = (blob) b.clone();
}
}
$ javac -Xlint t.java
t.java:7: clone() has protected access
in java.lang.Object
blob cpy = (blob) b.clone();
^
1 error
$
Object.clone() implements a shallow copy.
clone() as a public method, and
$ cat t.java class blob implementsCloneablepublic blob clone() throws CloneNotSupportedException return (blob) super.clone(); class t public static void main(Stringargs[]) blob b = new blob(); try blob cpy = b.clone(); catch (Exceptione) { } $ javac -Xlint t.java $
Object.clone() as in a shallow copy, and
clone().
clone() too.
Object.clone()
appropriately.