java内部类
2021-01-03 10:28
标签:ati mic auto ring add ted 优先 abs print 定义:在一个类内部声明一个类,叫做这个类的内部类 public class Neibu01 { 测试类 java内部类 标签:ati mic auto ring add ted 优先 abs print 原文地址:https://www.cnblogs.com/tilyougogannbare666/p/12990938.html
private String st1="abc";
private int in1=12;
class Neibu02{//内部类
int in2=21;//优先访问内部类成员
int in1=14;//优先访问内部类成员
public void shwo() {
System.out.println(st1);
System.out.println(in2);
}
}
}
// TODO Auto-generated method stub
//创建 外部类对象,第一种写法
Neibu01 neibu01=new Neibu01();
Neibu02 neibu02=neibu01.new Neibu02();
//第二种写法
Neibu02 neibu_02=new Neibu01().new Neibu02();
neibu02.shwo();
}
private String name="absc";
private int age=18;
public void show() {
String address="南京";
class Inner{
private String phone="15542665398";
public void show2() {
System.out.println(name);
System.out.println(Outer.this.age);
System.out.println(address);
System.out.println(this.phone);
}
}
Inner inner=new Inner();
inner.show2();
}
}
// TODO Auto-generated method stub
Outer outer=new Outer();
outer.show();
}