类中内部类中的方法访问外部类中变量的示例(转)

lass Day10_11 { public static void main(String[] args) { Outer.Inner oi = new Outer().new Inner(); oi.print(); } } class Outer { public int num = 10; class Inner { public int num = 20; public void print(){ int num = 30; System.out.println(num);//本方法中的局部变量 System.out.println(this.num);//内部类中的成员变量 System.out.println(Outer.this.num);//外部类中的成员变量 } } } ——————— 本文来自 TT海浅 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/u010698072/article/details/52093355?utm_source=copy

 

《类中内部类中的方法访问外部类中变量的示例(转)》 

如果只有一个num变量,那么完全就不用理会这么多了,直接num它就会自动搜索到 

 

    原文作者:frank1998819
    原文地址: https://blog.csdn.net/frank1998819/article/details/84926673
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞