<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                重寫字段是創建類的層級的結構。許多設計模式使用到它,但是這里我們只探索基本的功能。為了在類中使用重寫,需要這個類有一個父類(第2.3.2)。思考下面的例子: > Overriding ?elds is instrumental for creating class hierarchies. Many design patterns utilize it, but here we will explore only the basic functionality. In order to use overrides in a class, it is required that this class has a parent class (2.3.2). Let us consider the following example: ~~~ class Base { public function new() { } public function myMethod() { return "Base"; } } class Child extends Base { public override function myMethod() { return "Child"; } } class Main { static public function main() { var child:Base = new Child(); trace(child.myMethod()); // Child } } ~~~ 這里重要的組件是: > The important components here are: * Base 類,有一個方法 myMethod和一個構造函數 * Child類,繼承Base類也有一個方法 myMethod,通過 override關鍵字聲明 * Main 類,它的main方法創建一個Child類的實例,分配它到一個變量 child ,顯式的聲明類型為Base,然后在其上調用 myMethod() > * the class Base which has a method myMethod and a constructor, > * the class Child which extends Base and also has a method myMethod being declared with override, and > * the Main class whose main method creates an instance of Child, assigns it to a variable child of explicit type Base and calls myMethod() on it. 變量 child 被顯式的類型化為 Base 來突出一個重要的不同:在編譯器時類型被認為是 Base,但是運行時仍然查找正確的方法即類Child中的 myMethod。這是因為字段訪問在運行時是動態解析的。 > The variable child is explicitly typed as Base to highlight an important difference: At compile-time the type is known to be Base,but the runtime still ?nds the correct method myMethod on class Child. This is because ?eld access is resolved dynamically at runtime. Child 類可以訪問它重載的方法,通過調用 super.methodName(): > The Child class can access methods it has overriden by calling super.methodName(): ~~~ class Base { public function new() { } public function myMethod() { return "Base"; } } class Child extends Base { public override function myMethod() { return "Child"; } public function callHome() { return super.myMethod(); } } class Main { static public function main() { var child = new Child(); trace(child.callHome()); // Base } } ~~~ 繼承(第2.3.2節)中解釋了super()在一個新的構造函數中的使用。 > The section on Inheritance (Section 2.3.2) explains the use of super() from within a new constructor.
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看