[20-05-18][Thinking in Java 26]Java Inner Class 10 - Anonymous Inner Class 5
Posted mirai3usi9
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[20-05-18][Thinking in Java 26]Java Inner Class 10 - Anonymous Inner Class 5相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章
Hacker Rank: Two Strings - thinking in C# 15+ ways
Thinking in Java & Writing in Python