你是不是说多态阿? 你实现接口,并实现这个的接口不想定义为接口或者抽象类,那就得必须实现! //是不是说这样的格式? package test;public class TestCsdn1 implements Apartment { /** * @param args */ public static void main(String[] args) { Apartment a = new TestCsdn1(); }}interface Apartment { }
莫非是这个格式的? package csdn;public class TestDefault{ public static void main(String[] args) { IA a = new IA() { public void test(){System.out.println("interface class");} }; } } interface IA{ void test(); }
你实现接口,并实现这个的接口不想定义为接口或者抽象类,那就得必须实现!
//是不是说这样的格式?
package test;public class TestCsdn1 implements Apartment { /**
* @param args
*/
public static void main(String[] args) {
Apartment a = new TestCsdn1();
}}interface Apartment {
}
package csdn;public class TestDefault{
public static void main(String[] args) {
IA a = new IA() {
public void test(){System.out.println("interface class");}
};
}
}
interface IA{
void test();
}