本文共 1136 字,大约阅读时间需要 3 分钟。
The implements keyword is used in a class declaration to indicate that the class being declared provides implementations for all methods declared in the interface whose name follows the implements keyword.
The following example illustrates a class implements an interface and provides a detailed implementation for the interface’s methods:
/** * This represents payment interface */interface Payment { public void pay();}class CashPayment implements Payment { // method overriding @Override public void pay() { System.out.println("This is cash payment"); }}class CreditPayment implements Payment { // method overriding @Override public void pay() { System.out.println("This is credit card payment"); }}
Unlike extends keyword, a class can implement multiple interfaces. The interface names are separated by commas. For example:
interface A {}interface B {}class C implements A, B {}
转载地址:http://obgrn.baihongyu.com/