abstract class Contents
{
abstract public int value();
}
interface Destination
{
String readLabel();
}
public class Parcel3
{
private class PContents extends Contents//此内部类由抽象类Contents所派生
{
private int i;
PContents(int cn){i=cn;}
public int value(){return i;}
}
protected class PDestination implements Destination//此内部类实现了接口Destination
{
private String label;
private PDestination(String whereTo){label=whereTo; }
public String readLabel(){return label;}
}
public Destination dest(String s){return new PDestination(s);}
public Contents cont(int cn){return new PContents(cn);}
}
class pl3
{
public static void main(String[] args){
Parcel3 p=new Parcel3();
Contents c=p.cont(100);
Destination d=p.dest("Tanzania");
System.out.println(c.value());
System.out.println(d.readLabel());
}
}
今天才知道编译时和执行时可以不是同一个类,,
就拿这个例子来说,编译应是javac Parcel3.java
执行时而是:java pl3
搞了半天才搞明白....!!!!!!!!!!!