<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

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

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

    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);
    ??????}

    ????}

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

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

    posted on 2006-11-26 23:42 lotusswan 閱讀(507) 評論(0)  編輯  收藏 所屬分類: Tiger學習筆記
    主站蜘蛛池模板: 天天综合亚洲色在线精品| 久久夜色精品国产噜噜亚洲a| 美美女高清毛片视频黄的一免费 | 好吊色永久免费视频大全| 国产免费观看视频| 曰批全过程免费视频观看免费软件| 免费高清小黄站在线观看| 亚洲AV无码专区在线电影成人| 暖暖在线日本免费中文| 国产亚洲精品美女2020久久| 国产一区二区三区免费看| jizz在线免费播放| 亚洲国产精品嫩草影院在线观看 | 国产99精品一区二区三区免费| 亚洲国产小视频精品久久久三级 | 羞羞的视频在线免费观看| 亚洲精品国产精品乱码不卞 | 亚洲熟妇无码八AV在线播放| 日韩免费在线视频| 亚洲一级毛片免观看| 日韩免费电影在线观看| 一级毛片一级毛片免费毛片| 亚洲va中文字幕无码久久| 100000免费啪啪18免进| 亚洲精品中文字幕| 亚洲人成色77777| 免费在线视频你懂的| 日韩在线视精品在亚洲| 国产亚洲3p无码一区二区| 国产成人精品免费午夜app| 亚洲中文字幕无码久久| 国产亚洲精品无码拍拍拍色欲| 久久青草免费91线频观看不卡| 亚洲卡一卡二卡乱码新区| 亚洲乱码中文字幕手机在线| 9277手机在线视频观看免费| 色天使亚洲综合一区二区| 久久亚洲国产精品| 国产免费久久精品| 4455永久在线观免费看| 日韩在线视频免费|