博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
implements_Keyword
阅读量:3925 次
发布时间:2019-05-23

本文共 1136 字,大约阅读时间需要 3 分钟。

implements Java Keyword with Examples

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 {}

Summary

  • A single class may implement multiple interfaces.
  • If the implemented class does not provide an implementation for the interface’s methods, the class must be abstract.

转载地址:http://obgrn.baihongyu.com/

你可能感兴趣的文章
uva 1351 - String Compression(区间DP,好题,较难)
查看>>
判断一个串是否是由重复子串组成
查看>>
No Girlfriend(简单题)
查看>>
[F] Teacher's Problem(处理大数时,优化很重要)
查看>>
[J] Dumb Typo(题目很简单,比赛错在不该自己计算,应该用电脑跑一遍的)
查看>>
[1545] New Year 2014(数位DP,现放标程,待看)
查看>>
CF 149D Coloring Brackets(区间DP,好题,给配对的括号上色,求上色方案数,限制条件多,dp四维)
查看>>
Light OJ 1422 - Halloween Costumes (区间DP)
查看>>
poj 2559 Largest Rectangle in a Histogram(DP二维超内存,用一维或者用结构体)
查看>>
Ningbo [1217] Dinner(简单题,但是注意输出,pe3遍)
查看>>
Ningbo [1218] You are my brother(注意数组的大小)
查看>>
Ningbo [1219] Time(将数字转换成时钟那样的数字)
查看>>
Ningbo [1220] SPY(题目有点难懂,读懂题目题很简单)
查看>>
hdu 2476 String painter(区间DP,较难)
查看>>
sdut 1309 不老的传说问题(区间DP,难,值得好好看)
查看>>
uva 10688 - The Poor Giant(区间DP,较难,题目难懂,状态转移难。。。)
查看>>
poj 1738 An old Stone Game(此题数小则可用区间DP,数较大用一维数组或者GarsiaWachs算法),待续
查看>>
poj 1823 Hotel(线段树,整段更新)
查看>>
poj 3667 Hotel(此题跟poj 1823有共同点,都属于区间合并问题)
查看>>
hdu 1754 I Hate It(线段树,单点替换,求区间最值)
查看>>