- package com.itheima;
- class A {
- int x = 1;
-
- class B {
-
- int x = 2;
-
- void func() {
-
- int x = 3;
- //对于func中x,直接使用x,对class B中x可以是用this.x,因为func所在的当前对象this是B,
- //对于A中的x,可以用A.this.x表示this指向的是A
- System.out.println(x + " " + this.x + " " + A.this.x);
- }
- }
- }
- public class PrintTTT {
-
- public static void main(String[] args) {
- //调用内部类的方法,需要创建内部类的对象
- new A().new B().func();
- }
- }
复制代码
|