?? 5例子16.txt
字號:
interface Computable
{
public void add(int x,int y);
}
class A
{
void f(Computable c,int a,int b)
{
c.add(a,b); //c調用匿名類體中實現的接口方法(接口回調).
}
void g()
{ //在方法g中,調用方法f.
f(new Computable()
{
public void add(int x,int y) //匿名類實現接口方法
{
System.out.printf("\n%d與%d的和等于%d",x,y,x+y);
}
}
,12,34); //向方法傳遞實現了接口的匿名對象和兩個int型數據.
}
}
public class Example
{
public static void main(String args[])
{
A a=new A();
a.g();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -