public interface ClassInInterface { void howdy(); class Test implements ClassInInterface{ @Override public void howdy() { System.out.println("Howdy"); } public static void main(String[] args) { new Test().howdy(); } } }java编程思想中的一个例子。
匿名类如何 new interface1(){}.innerC.f1();
class Test implement interface1 {public static void main(String str[]) {innerc test=new innerc(); test.f1(); }}
难道是只在static中有用?加载的时候就调?
这么用,类名首字母最好大写。public static void main(String[] args) { interface1.innerC c = new interface1.innerC(); c.f1(); }
new 接口名(){
实现接口中的方法
。。
}.new 内部类类名()具体你可以看下内部类的教程,google一下有很多。
String str = "str";
void f1(){
System.out.println("inner");
}
}
}
Interface interface1 { class innerC {
String str = "str";
void f1(){
System.out.println("inner");
}
}
}这个内部类怎么用?
public interface ClassInInterface {
void howdy();
class Test implements ClassInInterface{
@Override
public void howdy() {
System.out.println("Howdy");
}
public static void main(String[] args) {
new Test().howdy();
}
}
}java编程思想中的一个例子。
new interface1(){}.innerC.f1();
{innerc test=new innerc();
test.f1();
}}
这么用,类名首字母最好大写。public static void main(String[] args) {
interface1.innerC c = new interface1.innerC();
c.f1();
}