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

2021-01-18 10:12

阅读:585

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


评论


亲,登录后才可以留言!