interface Inter
{
public abstract void show();
public abstract void show2();
}
class Outer
{
public void method()
{
/*
new Inter()
{
public void show()
{
System.out.println("show");
}
};
*/
//怎么调用呢?
/*
new Inter()
{
public void show()
{
System.out.println("show");
}
public void show2()
{
System.out.println("show2");
}
}.show();
*/
new Inter()
{
public void show()
{
System.out.println("show");
}
public void show2()
{
System.out.println("show2111111");
}
}.show2();
//多态
Inter i = new Inter()
{
public void show()
{
System.out.println("show");
}
public void show2()
{
System.out.println("show2");
}
};
i.show();
i.show2();
}
}
class InnerTest4
{
public static void main(String[] args)
{
Outer o = new Outer();
o.method();
}
}
|
|