欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > PPT文档下载  

    面向对象技术及语言-第8章.ppt

    • 资源ID:6613928       资源大小:232KB        全文页数:29页
    • 资源格式: PPT        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    面向对象技术及语言-第8章.ppt

    面向对象技术及语言 Object-Oriented Technology&Language,第8章 Interface&Inner Classes,主讲教师:饶若楠上海交通大学计算机科学与工程系,第8章 Interfaces&Inner Classes,8.1 Interfaces 8.1.1“multiple inheritance”in Java 8.1.2 Extending an interface with inheritance 8.1.3 Grouping constants 8.1.4 Initializing fields in interfaces 8.1.5 Nesting interfaces8.2 Inner Classes 8.2.1 Inner classes and upcasting 8.2.2 Inner classes in methods and scopes 8.2.3 Anonymous inner classes 8.2.4 The link to the outer class 8.2.5 Nested classes,第8章 Interfaces&Inner Classes,8.2.6 Referring to the outer class object 8.2.7 Reaching outward from a multiply-nested class 8.2.8 Inheriting frominner classes 8.2.9 Can inner classes be overriden 8.2.10 Local inner classes 8.2.11 Inner class identifiers8.3 Why inner classes?8.3.1 Closure&Callbacks 8.3.2 Inner classes&control frameworks,8.1 接口(Interface),所谓接口就是对操作规范的说明。通俗地说,接口只是说明函数应该做什么(What),但没有定义函数如何做(How),Elided/Iconic Representation(“lollipop”),8.1 接口Interface,1.接口的定义 接口的定义包括接口声明和接口体两部分。如下:public interface InterfaceName extends superInterfaceList/接口声明 type constantName=Value;/常量声明,可为多个 retumType methodName(paramList);/方法声明,可为多个例如:interface Shape public void draw();一个接口可以有多个父接口,用逗号隔开,子接口继承父接口中所有的常量和方法。,8.1 接口Interface,2.接口的实现 在类的声明中用implements子句来表示一个类使用某个接口,在类体中可以使用接口中定义的常量,而且必须实现接口中定义的所有方法。一个类可以实现多个接口,在implements子句中用逗号分隔。例如:public class Triangle implements Shape public void draw().,5.9 接口Interface,3.接口可以作为一种引用类型来使用。任何实现该接口的类的实例都可以存储在该接口类型的变量中,通过这些变量可以访问类所实现的接口中的方法。Java运行时系统动态地确定该使用哪个类中的方法。例如:Shape abc=new Triangle();,8.1接口Interface-例子,interface Collection int MAX_NUM=100;void add(Object obj);void delete(Object obj);Object find(Object obj);int currentCount();,class FIFOQueue implements collection void add(Object obj)void delete(Object obj)Object find(Object obj)int currentCount,8.1 接口Interface-例子,class InterfaceType public static void main(String args)Collection c=new FIIFOQueue();add(obj);,把接口作为一种数据类型可以不需要了解对象所对应的具体的类,而着重于它的交互界面,“multiple inheritance”in Java(p319-323),Because an interface has no implmentation at all-that is,there is no storage associated with an interface-theres nothing to prevent may interfaces from being combined.,Example:c08:Adventure.java(p320),Name collision when combining interfaces Example:c08:InterfaceCollision.java(p322),Extending an interface with inheritance(p323-324),You can add new method declarations to an interface by using inheritance,and you can also combine several interfaces into a new interface with inheritance.,Example:c08:HorrorShow.java(p323),Grouping constants(p324-327),Because any fields you put into an interface are automatically static and final,the interface is a convenient tool for creating groups of constant.,Example:c08:Months.java(p324)c08:Month.java(p325),Initializing fields in interfaces(p327-328),Fields defined in interfaces are automatically static and final.Those cannot be“blank finals,”but they can be initialized with nonconstant expressions.,Example:c08:RandVals.java(p327)c08:TestRandvals.java(p327),Nesting interfaces(p328-331),Interfaces may be nested within classes and within other interfaces.,Example:c08:NestingInterfaces.java(p328),Inner classes(p331-p333),Its possible to place a class definition within another class definition.This is called an inner class.,Example:c08:Parcel1.java(p331),Inner classes and upcasting(p333-p335),Inner classes really come into their own when you start upcasting to a base class,and in particular to an interface.,Example:c08:Destination.java(p333)c08:Contents.java(p334)c08:TestParcel.java(p334),Inner classes in methods and scopes(p335-p338),Inner classes can be created within a method or even an arbitrary scope.,Example:c08:Wrapping.java(p336)c08:Parcel4.java(p336)c08:Parcel5.java(p334),Anonymous inner classes(p338-p342),Example:c08:Parcel6.java(p338)c08:Parcel7.java(p339)c08:Parcel8.java(p339)c08:AnonymousConstructor.java(p340)c08:Parcel9.java(p341),The link to the outer class(p342-p344),When you create an inner class,an object of that inner class has a link to the enclosing object that made it.,Example:c08:sequence.java(p342),Nested classes(p344-p347),static inner classes.,Example:c08:Parcel10.java(p345)c08:IInterface.java(p346)c08:TestBed.java(p346),Referring to the outer class object(p347-p348),Example:c08:Parcel11.java(p347),Reaching outward from a multiply-nested class(p348-p349),Example:c08:MultiNestingAccess.java(p348),Inheriting from inner classes(p349),Example:c08:InheritInner.java(p349),Can inner classes be overriden?(p350),Example:c08:BigEgg.java(p350),Local inner classes(p352),Example:c08:LocalInnerClass.java(p352),Inner class identifier(p354),LocalInnerClass$2.class,Why inner classes?(p354-357),Example:c08:MultiInterfaces.java(p355)c08:MultiImplementation.java(p356),Closures&Callbacks(p357-360),Example C08:Callbacks.java(p358),Inner classes&control frameworks(p360-367),Example C08:Controller:Event.java(p361)c08:Controller:Controller.java(p362)c08:GreenhouseControls.java(p363-p366),

    注意事项

    本文(面向对象技术及语言-第8章.ppt)为本站会员(小飞机)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开