码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2020-05-19 00:24:56      阅读:61      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!