[20-05-18][Thinking in Java 26]Java Inner Class 10 - Anonymous Inner Class 5

2021-01-18 10:16

阅读:731

标签:show   pre   thinking   rgs   void   stat   public   his   ack   

1 package test_16_3;
2 
3 public interface Inter {
4 
5     String show();
6 }

 

 1 package test_16_3;
 2 
 3 public class Outter {
 4 
 5     public Inter inter() {
 6         return new Inter() {
 7             
 8             
 9             
10             @Override
11             public String show() {
12                 System.out.println("show");
13                 
14                 return "this is Outter.Inner.show()";
15             }
16         };
17     }
18     
19     public static void main(String[] args) {
20         
21         Outter outter = new Outter();
22         Inter inter = outter.inter();
23         System.out.println(inter.show());
24     }
25 }

 

结果如下:

show
this is Outter.Inner.show()

[20-05-18][Thinking in Java 26]Java Inner Class 10 - Anonymous Inner Class 5

标签:show   pre   thinking   rgs   void   stat   public   his   ack   

原文地址:https://www.cnblogs.com/mirai3usi9/p/12913845.html


评论


亲,登录后才可以留言!