标题:关于接口的问题求指教?
取消只看楼主
清微御宇
Rank: 6Rank: 6
来 自:开封
等 级:侠之大者
威 望:2
帖 子:318
专家分:497
注 册:2012-1-15
结帖率:100%
已结贴  问题点数:18 回复次数:1 
关于接口的问题求指教?
程序代码:
package test;

interface ISport {
    void run();
}

class Athelete implements ISport {
    public void run() {
        System.out.println("三级跳");
    }
}

class Students implements ISport {
    public void run() {
        System.out.println("我随便跑跑");
    }
}

class CollegeStudent extends Students {
    public void study() {
        System.out.println("好好学习,天天向上");
    }
}

public class AnyTest {
    public static void main(String[] args) {
        ISport i = new Athelete();
        i.run();
        i = new Students();
        i.run();
        i = new CollegeStudent();
        i.run();
        i.study();// 为山么i无法引用到设个方法?i=new CollegeStudent();
        CollegeStudent name = new CollegeStudent();
        name.study();

    }
}
搜索更多相关主题的帖子: test 接口 三级跳 
2012-11-02 20:09
清微御宇
Rank: 6Rank: 6
来 自:开封
等 级:侠之大者
威 望:2
帖 子:318
专家分:497
注 册:2012-1-15
得分:0 
回复 2楼 lz1091914999
ISport随手写的,上转型已经了解了,谢谢,这里好少?半天也木人回差点跑到休闲区发了!!!

Stay hungry , Stay foolish!
2012-11-04 20:15



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-385707-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.406843 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved