两个接口为:public interface Contents
{
int value();
}public interface Destination
{
String readLabel();
}一个包含内部类的类为:
public class Goods
{
private class Content implements Contents
{private int i=11;
public int value()
{
return i;
}
}
protected class GDestination implements Destination
{
private String label;
private GDestination(String whereTo)
{
label=whereTo;
}
public String readLabel()
{return label;
}
}
public Destination dest(String s) {return new GDestination(s);
}

public Contents cont() {return new Content();
}
}这两句作何理解,public+接口名+方法?这是什么?是实现接口吗?但是接口中无此方法啊?

解决方案 »

  1.   

    public Destination dest(String s) {return new GDestination(s);}public Contents cont() {return new Content();}上面两句都是定义一个函数,函数返回值是实现了对应接口的类的对象。
      

  2.   

    public Destination dest(String s)  {return new GDestination(s);
    }public Contents cont() {return new Content();
    }两个普通方法,返回实现了接口的类的对象
      

  3.   

    看看java的多态吧调用这个方法,就会得到一个实现了Destination接口的对象
      

  4.   

    普通方法:访问权限+返回类型+方法名
    public+接口名+方法 接口名就是返回类型啊