Cheug's Blog

当前位置:网站首页 / JAVA / 正文

使用内部类补齐代码

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.