<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    lotusswan

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      11 Posts :: 0 Stories :: 4 Comments :: 0 Trackbacks

    為了運(yùn)用多態(tài)性,當(dāng)編寫子類時(shí),你肯定會(huì)覆寫超類的方法。當(dāng)你覆寫超類的方法時(shí),你是否想到過更改方法的返回類型。如果你沒有,那祝賀你,你不曾為此煩惱過;如果你想到過,那你肯定是非常的郁悶。在Java 5.0以前,你是無法更改超類定義的方法的返回類型的。不過當(dāng)你使用Java 5.0以后,你會(huì)驚喜地發(fā)現(xiàn),此煩惱不復(fù)存在了。

    下面的示例顯示了這一新特性的用法:

    package ?com.jiang.tiger.chap1;

    class ?Point2D? {
    ??????
    protected ? int ?x,?y;

    ??????
    public ?Point2D(?)? {
    ????????
    this .x = 0 ;
    ????????
    this .y = 0 ;
    ??????}

    ??
    ??????
    public ?Point2D( int ?x,? int ?y)? {
    ????????
    this .x? = ?x;
    ????????
    this .y? = ?y;
    ??????}

    ??????
    ??????
    public ?String?toString()? {
    ??????????
    return ? " the?position?is?x?=? " ? + ?x? + ? " ,y?=? " ? + ?y?;
    ??????}

    ????}


    ????
    class ?Point3D? extends ?Point2D? {
    ??????
    protected ? int ?z;

    ??????
    public ?Point3D( int ?x,? int ?y)? {
    ????????
    this (x,?y,? 0 );
    ??????}

    ?
    ??????
    public ?Point3D( int ?x,? int ?y,? int ?z)? {
    ????????
    this .x? = ?x;
    ????????
    this .y? = ?y;
    ????????
    this .z? = ?z;?
    ??????}

    ??????
    ??????
    public ?String?toString()? {
    ??????????
    return ? " the?position?is?x?=? " ? + ?x? + ? " ,y?=? " ? + ?y? + ? " ,z=? " ? + ?z;
    ??????}

    ????}


    ????
    class ?Position2D? {
    ??????Point2D?location;
    ?
    ??????
    public ?Position2D(?)? {
    ????????
    this .location? = ? new ?Point2D(?);
    ??????}


    ??????
    public ?Position2D( int ?x,? int ?y)? {
    ????????
    this .location? = ? new ?Point2D(x,?y);
    ??????}


    ??????
    public ?Point2D?getLocation(?)? {
    ????????
    return ?location;
    ??????}

    ????}


    ????
    public ? class ?Position3D? extends ?Position2D? {
    ??????Point3D?location;
    ?
    ??????
    public ?Position3D( int ?x,? int ?y,? int ?z)? {
    ????????
    this .location? = ? new ?Point3D(x,?y,?z);
    ??????}


    ??????
    public ?Point3D?getLocation(?)? {
    ????????
    return ?location;
    ??????}

    ????????????
    ??????
    public ? static ? void ?main(String[]?args)? {
    ??????????Position2D?position?
    = ? new ?Position3D( 12 ,? 23 ,? 36 );
    ??????????Point3D?clone?
    = ?(Point3D)position.getLocation();
    ??????????System.out.println(clone);
    ??????}

    ????}

    為驗(yàn)證功能是否正確,我們看看運(yùn)行結(jié)果:

    the position is x = 12,y = 23,z= 36

    posted on 2006-11-26 23:42 lotusswan 閱讀(507) 評(píng)論(0)  編輯  收藏 所屬分類: Tiger學(xué)習(xí)筆記
    主站蜘蛛池模板: 亚洲AV一二三区成人影片| 亚洲精品自产拍在线观看| 亚洲成A人片在线播放器| 无码国产精品一区二区免费式直播| 亚洲热妇无码AV在线播放| 一级特黄录像免费播放肥| 亚洲国产成人片在线观看| 亚洲免费人成在线视频观看| 亚洲Av无码专区国产乱码DVD| 在线涩涩免费观看国产精品| 亚洲国产女人aaa毛片在线| 日韩免费人妻AV无码专区蜜桃| 亚洲国产精品不卡在线电影| 91免费国产精品| 亚洲videos| 国产成人一区二区三区免费视频 | 国产成人免费午夜在线观看| 亚洲毛片基地日韩毛片基地| 97在线观免费视频观看| 日韩欧美亚洲国产精品字幕久久久| 免费国产人做人视频在线观看| 亚洲阿v天堂在线2017免费| 精品久久久久久亚洲| 蜜桃AV无码免费看永久| 亚洲人成色777777精品| 亚洲国产天堂久久综合| 国偷自产一区二区免费视频 | 亚洲av色香蕉一区二区三区| 四虎影视在线永久免费看黄| 日韩精品无码免费专区午夜 | 成年性羞羞视频免费观看无限| 337P日本欧洲亚洲大胆精品| 中文亚洲AV片不卡在线观看| 最近中文字幕无免费| 亚洲av无码成人精品区一本二本| 国产AV无码专区亚洲AV手机麻豆 | 亚洲精品福利网站| 国产无遮挡吃胸膜奶免费看| 久久久久国产精品免费免费不卡| 亚洲日韩AV一区二区三区四区| 国产av无码专区亚洲av果冻传媒|