- 1、本文档共125页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
第5章继承、接口与泛型资料
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * class TalkingClock { public TalkingClock(int interval, boolean beep) { this.interval = interval; this.beep = beep; } public void start() { ActionListener listener = new TimePrinter(); Timer t = new Timer(interval, listener); t.start(); } private int interval; private boolean beep; private class TimePrinter implements ActionListener { public void actionPerformed(ActionEvent event) { Date now = new Date(); System.out.println(At the tone, the time is + now); if (beep) Toolkit.getDefaultToolkit().beep(); } } } * 5.15 内部类inner class The TimePrinter class has no instance field or variable named beep. Instead, beep refers to the field of the TalkingClock object that created this TimePrinter. This is quite innovative. Use of an Inner Class to Access Object State * 5.15 内部类inner class Traditionally, a method could refer to the data fields of the object invoking the method. An inner class method gets to access both its own data fields and those of the outer object creating it. How to do this? Use of an Inner Class to Access Object State * 5.15 内部类inner class an object of an inner class always gets an implicit reference to the object that created it. Use of an Inner Class to Access Object State * 5.15 内部类inner class This reference is invisible in the definition of the inner class. However, to illuminate the concept, let us call the reference to the outer object outer. Then, the actionPerformed method is equivalent to the following: public void actionPerformed(ActionEvent event) { Date now = new Date(); System.out.println(At the tone, the time is + now); if (outer.beep) Toolkit.getDefaultToolkit().beep(); } Use of an Inner Class to Access Object State * 5.15 内部
您可能关注的文档
最近下载
- 厦门东部三期垃圾焚烧发电厂项目环境影响报告书.pdf
- 2022火力发电厂化学系统智能化设计导则.docx
- MQY-202使用说明V1.2(增加CPA标志及使用说明).pdf VIP
- 国际课程课件系列之物理boardworks 5. Momentum v1.1.ppt
- 豫新船舶公司(原泥矶船厂)技术改造项目环评(新版环评)环境影响报告表.pdf
- 五年级下册综合实践活动课件-中国结——鞭炮结 全国通用 20张.pptx
- 企业风险防控清单.pdf
- 《风险管理》教案.docx
- 幼儿园保教设施设备配标准(2023版).doc
- INOVANCE汇川-中型PLC编程软件使用手册-AM400 AM600 AP700 AC700 AC800中文.pdf
文档评论(0)