- 1、本文档共11页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
java of Ineritance and Polymorphism
Inheritance and Polymorphism
What is the best way to design these classes so to avoid redundancy? The answer is to use inheritance. This chapter focuses on discussing Inheritance and Polymorphism, and it contains twelve objectives that we should study. They are developing a subclass from a superclass through inheritance (?1.2), invoking the superclass抯 constructors and methods using the super keyword (?1.3), overriding instance methods in the subclass (?1.4), distinguishing differences between overr iding and overloading (?1.5), exploring the toString() method in the Object class (?1.6), discovering polymorphism and dynamic binding (?1.7-11.8), describing casting and explain why explicit downcasting is necessary (?1.9), exploring the equals() meth od in the Object class (?1.10), storing, retrieving, and manipulating objects in an ArrayList (?1.11), implementing a Stack class using ArrayList (?1.12), restricting access to data and methods to subclasses using the protected visibility modifier (?1. 13), prevent class extending and method overriding using the final modifier (?1.14).
11.2 Superclass and Subclass:
In Java terminology, a class C1 extended from anther class C2 is called a subclass, and C2 is called a superclass. A superclass is also referred to as a parent class, or a base class, and a subclass as a child class, an extended class, or a derived class. A subclass inherits accessible data fields and methods from its superclass and may also add new data fields and methods. And superclass抯 constructor are not inherited. They are invoked explicitly or implicitly. The following points regarding inheritance are worthwhile to remember:
1 Contrary to the conventional interpretation, a subclass is not a subset of its super class. In fact, a sub class usually contains more information and methods than its superclass.
2 Private data fields in a superclass are not accessible outside the class.
3 Not all is-a relationships should be modeled using inheritan
您可能关注的文档
- IELTS 旅行度假景词汇.doc
- III级人员考试试题基础考试).doc
- IL-17在消化道炎中的发生及促炎症、抗感染作用.doc
- IMF各国汇率制度安2006.doc
- Impact of unt.doc
- In accordace with the requirements of the technical standards and technical regulations work.doc
- In Isolate Hills of Asia, New Roads to Speed Trade.doc
- Including he metal surface coating layer mainly for all kinds of lining.doc
- INDICATION FOR PEDIATRIC.doc
- Individualsm.doc
文档评论(0)