為什么我的大括號(hào)總是錯(cuò)!
package interfacetest;
public class TelphoneTest {
?public static void main(String[] args) {
??Telephone tel1 = new CellPhone();
??tel1.call();
??tel1.message();
??Telephone tel2 = new SmartPhone();
??tel2.call();
??tel2.message();
??
??
??IPlayGame ip1 = new SmartPhone();
??ip1.PlayGame();
??IPlayGame ip2 = new Psp();
??ip2.PlayGame();
??
??IPlayGame ip3 = new IPlayGame(){
???@Override
???public void PlayGame() {
????// TODO Auto-generated method stub
???System.out.println("使用匿名內(nèi)部類(lèi)的方式");
???}
???
??}
?}
}
?
2016-08-21
你最后漏了一句ip3.playGame();?
你必須要通過(guò) 對(duì)象名ip3 把你的playGame方法里的內(nèi)容 輸出出來(lái)
2015-06-21
};然后沒(méi)有錯(cuò)了,運(yùn)行結(jié)果為
通過(guò)鍵盤(pán)打電話!
通過(guò)鍵盤(pán)發(fā)短信!
通過(guò)語(yǔ)音打電話!
通過(guò)語(yǔ)音發(fā)短信!
具有了玩游戲的功能!
具有了玩游戲的功能!
為什么最后一句沒(méi)有輸出!使用匿名內(nèi)部類(lèi)的方式,這個(gè)沒(méi)有輸出!