匿名內(nèi)部類實現(xiàn)接口
package project3;
public class Initail {
public static void main(String[] args) {
// TODO Auto-generated method stub
Telphone tell = new CellPhone();
tell.call();
tell.message();
Telphone tel2 = new SmartPhone();
tel2.call();
tel2.message();
IPlayGame ip1 = new SmartPhone();
ip1.playGame();
IPlayGame ip2 = new Psp();
ip2.playGame();
}
IPlayGame ip4 = new IPlayGame() {
@Override
public void playGame() {
// TODO Auto-generated method stub
System.out.println("使用匿名內(nèi)部類方法實現(xiàn)接口");
}
};
ip4.playGame();//這個錯了
}
//這是原因,不知道怎么錯的,求大神解釋:Syntax error on token "playGame", Identifier expected after this token
2018-04-08
ip4 上面一行多了個括號 去掉
2018-04-08
ip2.palyGame();下面的括號位置不對,加到最下面。
2018-04-08
在最后面加上一個括號