?? animal.java
字號:
//演示(匿名)內部類實現接口
interface Animal
{
void eat();
void sleep();
}
class Zoo
{
/*
class Tiger implements Animal
{
public void eat()
{
System.out.println("Tiger eat");
}
public void sleep()
{
System.out.println("Tiger sleep");
}
}
*/
Animal GetAnimal()
{
return new Animal()
{
public void eat()
{
System.out.println("Animal eat");
}
public void sleep()
{
System.out.println("Animal sleep");
}
};
}
}
class Test
{
public static void main(String[] args)
{
Zoo z = new Zoo();
Animal a = z.GetAnimal();
a.eat();
a.sleep();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -