package com.shrimpking.t1;
/**
* Created by IntelliJ IDEA.
*
* @Author : Shrimpking
* @create 2024/9/28 18:36
*/
class MemberInnerDemo{
//外部类
private int x = 1;
private int y = 2;
public class Inner{
//成员内部类
private int y = 3;
public void method(){
System.out.println(x); //直接访问外部类的属性
System.out.println(y); //内外均有相同变量时,访问内部的
System.out.println(this.y); //访问外部的
System.out.println(MemberInnerDemo.this.x); //访问外部
}
}
}
public class MemberInnerClassApp5_2
{
public static void main(String[] args)
{
//创建成员内部类对象
MemberInnerDemo.Inner inner = new MemberInnerDemo().new Inner();
inner.method();
}
}
MemberInnerClassApp5_2
最新推荐文章于 2024-11-10 09:25:34 发布