- 10
- 0
- 约1.19万字
- 约 37页
- 2017-07-02 发布于湖北
- 举报
chapter 10 Abstract Classes and Interfaces概要1
Introduction To Java Programming College Of Software Liu. Zhi Gang Email:dqpilzg@163.com Contents 10.1 Abstract Class Definition (Page.342)Sometimes a super class is so abstract that it cannot have any specific instances. Such a class is referred to as an abstract class. Abstract classes are like regular classes with data and methods, but you cannot create instances of abstract classes using the new operator. Example I Exercise II Exercise II Exercise III Eclipse Add a abstract Class Override a abstract method in the sub class Contents Definition (Page.347)An interface is a class that only contains constants and abstract methods. In many ways, an interface is similar to an abstract class, but an abstract class can contain variables and concrete methods as well as constants and abstract methods. As like an abstract class, you cannot create an instance from an interface using the new operator Declaring Example Exmaple I Example I Example I 变形 Eclipse Add a interface Add a class which to implement from a interface Example II Student Exercise 寻找你身边的一个实际问题,编写程序加以解决。例如,童话故事中的两个人物:小红帽和狼。他们都有相同的行为:到达(arrive)、见面(meet)、交谈(talk)。另外,小红帽有年龄属性及采花行为,而狼会吃人。 Contents 深入的知识(学生了解即可) Part I Abstract Classes 1 Part II Interface 2 Part III The Difference Between Them 3 include Doesnt include Constructor The subclass must have relation The subclass can have no relation Service Only support single inheritance Support multiple inheritance Inheritance Can have the implements and any modifiers, but must have one or more abstract method. Only have the definition (must be public abstract method) method include Doesnt include variable include Include (must be static) constant Abstract Class Interface 不同点 相同点:都不支持实例化 记忆窍门: (1)常量:接口和抽象类都可以包含,但是接口中的常量是static类型的,而抽象类没有限制 (2)变量:接口中不能有变量,抽象类可以有 (2)构造方法:接口中没有,抽象类中有 (3)方法:接口中的方法只能有定义,必须是public abstract类型的抽象方法,抽象类中的方法可以有实现,也可以是只有定义,抽象类必须拥有一个以上的抽象方法 (4)继承:接口可以实现多重继承,抽象类只能单继承 (5)对外服务:继承实现接口的子类可以是不相关的,继承实现抽象类的子类必须是相关的 duck swim GuaGuaJiao RedDuck Gr
您可能关注的文档
- Changes_in_the_Way_We_Live概要1.ppt
- CH9 核酸生物合成改概要1.ppt
- Chap001 金融机构习题解答概要1.doc
- Chap 2Intro to UML概要1.ppt
- Chap.4 筹资来源与工具概要1.ppt
- chap008Using Discounted Cash Flow Analysis to Make Investment Decisions(财务管理,Matthew Will)概要1.ppt
- chap 1化学史概要1.pptx
- chap007Cash Flow Analysis(财务报表分析,台湾中兴大学)概要1.ppt
- Chap. 1 Introduction概要1.ppt
- chap010Prospective Analysis(财务报表分析,台湾中兴大学)概要1.ppt
原创力文档

文档评论(0)