3

这在 Java 中究竟意味着什么?

接口定义了实现类的契约

4

2 回答 2

8

这意味着通过实现接口,类同意实现接口指定的所有功能。

于 2012-08-31T14:00:09.180 回答
0

In interface you simply declare the members(say methods). For example

public Interface Product{

protected void getProduct();
protected void getProductId();
}

Whereas in a class you can implement the above interface and can define these methods...

public class ProductClass implements Product{

protected void getProduct()
{
    System.out.println("Product is: ");
}
protected void getProductId()
{
    System.out.println("Product Id is: ");
}
}

So you can see the methods declared in interface are defined in the class. Basically, you can say that interface just provides the blueprint but class actually does the whole work.

于 2012-08-31T14:19:00.547 回答