使用内部类补齐代码
2019-03-17 / JAVA / 802 次围观 / 0 次吐槽 /试题:按照要求,补齐代码
interface Inter { void show(); }
class Outer { //补齐代码 }
class OuterDemo {
public static void main(String[] args){
Outer.method().show();
}
}
要求在控制台输出“HelloWorld”
//有多种写法这只是其中一种 interface Inter { void show();} class Outer { public static Inter method(){ return new Inter(){ @Override public void show() { System.out.print("HelloWorld"); } }; } } class OuterDemo{ public static void main(String[] args) { Outer.method().show(); } }
Powered By Cheug's Blog
Copyright Cheug Rights Reserved.
额 本文暂时没人评论 来添加一个吧
发表评论