匿名内部类面试题

/**
 * 匿名内部类面试题
 * 补全代码,并向控制台中输出HelloWord
 * 
 * interface Inter3{
 *	void show();
 *}
 *class Outer3{ //补全代码
 *}
 *public class InterMianShi {
 *	public static void main(String[] args){
 *		Outer3.method3().show();
 *		
 *		 //1:Outher.method()可以看出method应该是Outher中的一个静态方法
 *		 //2:Outher.method.().show()可以看出method()方法的返回值类型是一个对象
 *		//又由于接口Inter中有一个show方法,所以认为method()方法的返回值类型是一个接口
 *		 
 *	}
 *}
 * @author Administrator
 *
 */
interface Inter3{
	void show();
}
class Outer3{
	public static Inter3 method3(){
		return new Inter3(){
			@Override
			public void show() {
				// TODO Auto-generated method stub
				System.out.println("HelloWord");
			}
		};
	}
}
public class InterMianShi {
	public static void main(String[] args){
		Outer3.method3().show();
		/**
		 * 1:Outher.method()可以看出method应该是Outher中的一个静态方法
		 * 2:Outher.method.().show()可以看出method()方法的返回值类型是一个对象
		 * 又由于接口Inter中有一个show方法,所以认为method()方法的返回值类型是一个接口
		 */
	}
}

猜你喜欢

转载自blog.csdn.net/weimeig/article/details/80193215