Anonymous Internal Class Interview Questions

/**
 * Anonymous internal class interview questions
 * Complete the code and output HelloWord to the console
 *
 * interface Inter3{
 *	void show();
 *}
 *class Outer3{ //Complete code
 *}
 *public class InterMianShi {
 *	public static void main(String[] args){
 *		Outer3.method3().show();
 *		
 * //1: Outher.method() It can be seen that method should be a static method in Outher
 * //2:Outher.method.().show() It can be seen that the return value type of the method() method is an object
 * //Because there is a show method in the interface Inter, it is considered that the return value type of the method() method is an interface
 *		 
 *	}
 *}
 * @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() can see that method should be a static method in Outher
		 * 2: Outher.method.().show() It can be seen that the return value type of the method() method is an object
		 * Since there is a show method in the interface Inter, the return value type of the method() method is considered to be an interface
		 */
	}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325936262&siteId=291194637