国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

TIJ swot_JAVA的初學者(四)

2019-11-18 14:07:39
字體:
來源:轉載
供稿:網友

  1.4 Reusing the implementation

We could reuse a class by instantiate it as an obect or place an object of this class inside a new class(this is called composition or aggregation).

1.5 Inheritance: reusing the interface

Inheritance enables us to clone an existing class and make additions and modifications to the clone.The modified “clone” will reflects the change in the original class.Do we need to modify the clone class?

Inheritance rePResents a certain kind of relationship between classes/types using the concept of base types and derived types. A base type contains all of the characteristics and behaviors that are shared among the types derived from it.

By inheritance, we could add new function to the interface or change the behavior of an existing base-class function.This referred to as overriding that function.

1.5.1 Is-a vs. is-like-a relationship

If inheritance override only base-class function, this is a pure substitution.Like “a circle is a shape“.

When we add new interface elements to a derived type, this substitution isn't perfect.This can be described as an is-like-a relationshipe. SUCh as “heap pump is like a cooling system".

1.6 Interchangeable objects with polymorphism

By inheritance, we could create a lot more new objects, which has similarities as the base objects. But is that all?

Let me think...We got too many methods or functions have the same name or identification as a result of inheritance. Polymorphism is the mechanism of OOP to pick up the right one automatically. But we dont need to know how it does this at this stage.

In a non-OOP compiler, the function call generated is early binding, that means the absolute address is needed. In OOP, the program cannot determine the affress of the code until run-time. This concept is called late binging. To perform this, java uses a special bit of code in lieu of the absolute call. This code calculates the address of the function body, using information stored in the object.This is Java's dynamic binding.

upcast..

1.6.2 Abstract base classes and interfaces

To declare an class abstract, we prevent creating an object of that class.

We can declare a class or a method as abstract, but abstract method can only be created inside an abstract class.

To take the concept of abstract class one step further, we could declare a class as an interface. Any implementation of methods is strictly forbidden in an interface.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 饶河县| 卢湾区| 九龙城区| 浦城县| 郯城县| 黔西| 滕州市| 宣恩县| 延庆县| 天水市| 平湖市| 新乡市| 乌兰县| 延吉市| 定南县| 泾川县| 黎川县| 鄂伦春自治旗| 景洪市| 霍城县| 钦州市| 四子王旗| 肇东市| 额敏县| 南丰县| 扶绥县| 静安区| 平江县| 宁河县| 五河县| 武宣县| 电白县| 凤台县| 嘉鱼县| 射阳县| 习水县| 佛学| 尼玛县| 红桥区| 蚌埠市| 新建县|