这在 Java 中究竟意味着什么?
接口定义了实现类的契约
这意味着通过实现接口,类同意实现接口指定的所有功能。
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.