- 1、本文档共117页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
5 Java面向对象思想的和概念
对于this的第二种用法(作用),看以下例子 设计一个程序测试一下类有无public访问控制符的区别? 自己写个程序测试一下成员变量或成员函数的访问权限? 类中的常量 类中的常量是被该类的所有对象共享的,因此,常量应该声明为final static。 例如,Math类中的常量PI是这样定义的: final static double PI = 3.14159265358979323846 Immutable Objects and Classes Example What Class is Immutable? 然而,不好的重载兼容,会发生有歧义的重载: public class AmbiguousOverloading { public static void main(String[] args) { System.out.println(max(1, 2)); }? public static double max(int num1, double num2) { if (num1 num2) return num1; else return num2; } public static double max(double num1, int num2) { if (num1 num2) return num1; else return num2; } } 多态(Polymorphism) Polymorphism源于希腊文,意思是“多种形式” 定义:使用父类对象的地方都可以使用子类的对象,这就是所谓的多态。 简单来说:多态意味着父类型的变量可以引用子类型的对象。 Polymorphism, Dynamic Binding and Generic Programming When the method m(Object x) is executed, the argument x’s toString method is invoked. x may be an instance of GraduateStudent, Student, Person, or Object. Classes GraduateStudent, Student, Person, and Object have their own implementation of the toString method. Which implementation is used will be determined dynamically by the Java Virtual Machine at runtime. This capability is known as dynamic binding. Dynamic Binding Dynamic binding works as follows: Suppose an object o is an instance of classes C1, C2, ..., Cn-1, and Cn, where C1 is a subclass of C2, C2 is a subclass of C3, ..., and Cn-1 is a subclass of Cn. That is, Cn is the most general class, and C1 is the most specific class. In Java, Cn is the Object class. If o invokes a method p, the JVM searches the implementation for the method p in C1, C2, ..., Cn-1 and Cn, in this order, until it is found. Once an implementation is found, the search stops and the first-found implementation is invoked. Method Matching vs. Binding Matching a method signature and binding a method implementation are two issues. The compiler finds a matching method according to parameter type, number of parameters, and order of th
您可能关注的文档
- 3D MAX菜鸟入门教程的.doc
- 37-再论媒介时间_电的子媒介时间观之存在_影响与反思.pdf
- 378条易读错的成语的.doc
- 3DMAX灯光篇的.ppt
- 3CPU-1的.ppt
- 3DMAX完美教程第6章的 材质和贴图.ppt
- 3dmax软件介绍的.ppt
- 3DXML文件格式解析嫉陌应用.pdf
- 3D中 法线 概念 数训魔基础.doc
- 3D游戏编程大师技巧的.doc
- 金融产品2024年投资策略报告:积极适应市场风格,行为金融+机器学习新发现.pdf
- 交运物流2024年度投资策略:转型十字路,峰回路又转(2023120317).pdf
- 建材行业2024年投资策略报告:板块持续磨底,重点关注需求侧复苏.pdf
- 宏观2024年投资策略报告:复苏之路.pdf
- 光储氢2024年投资策略报告:复苏在春季,需求的非线性增长曙光初现.pdf
- 公用环保2024年投资策略报告:电改持续推进,火电盈利稳定性有望进一步提升.pdf
- 房地产2024年投资策略报告:聚焦三大工程,静待需求修复.pdf
- 保险2024年投资策略报告:资产负债匹配穿越利率周期.pdf
- 政策研究2024年宏观政策与经济形势展望:共识与分歧.pdf
- 有色金属行业2024年投资策略报告:新旧需求共振&工业原料受限,构筑有色大海星辰.pdf
文档评论(0)