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

[20-05-18][Thinking in Java 25]Java Inner Class 9 - Anonymous Inner Class 4

时间:2020-05-19 01:04:41      阅读:56      评论:0      收藏:0      [点我收藏+]

标签:ati   thinking   return   sys   span   stat   结果   think   ret   

 1 package test_16_2;
 2 
 3 public class Outter {
 4     
 5     public Outter() {
 6         
 7     }
 8     
 9     public Outter(int i) {
10         
11         this.i = i;
12     }
13 
14     private int i = 1;
15     
16     private void show() {
17         System.out.println("this is " + i);
18     }
19     
20     public Outter outter(int x) {
21         
22         return new Outter(x) {
23             
24             {
25                 i = x;
26                 show();
27             }
28         };
29     }
30     
31     public int getI() {
32         
33         return i;
34     }
35     
36     public static void main(String[] args) {
37         
38         Outter outter = new Outter();
39         outter.outter(10);
40         System.out.println(outter.getI());
41     }
42 }

 

结果如下:

this is 10
10

[20-05-18][Thinking in Java 25]Java Inner Class 9 - Anonymous Inner Class 4

标签:ati   thinking   return   sys   span   stat   结果   think   ret   

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

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