假设我有这个界面:
public interface IBox
{
public void setSize(int size);
public int getSize();
public int getArea();
//...and so on
}
我有一个实现它的类:
public class Rectangle implements IBox
{
private int size;
//Methods here
}
如果我想使用接口iBox,我实际上不能创建它的实例,如下所示:
public static void main(String args[])
{
Ibox myBox=new Ibox();
}
正当所以我必须这样做:
public static void main(String args[])
{
Rectangle myBox=new Rectangle();
}
如果这是真的,那么接口的唯一目的就是确保实现接口的类具有接口所描述的正确方法?或者界面还有其他用途吗?