成员内部类他的一些修饰符
* private:能够保证内部类的数据的安全性
* static:静态的成员内部类
* 被static 修饰的成员方法只能访问外部类中静态的成员(必须使用private修饰)!
* //静态的成员内部类中成员的访问方式
//外部类名.内部类名 对象名=new 外部类名.内部类名();
//定义外部类
class Outer4{
public int num=100;
public static int num2=50;
//加入static 修饰的成员内部类
static class Inner4{//成员方法可以静态可以非静态
//定义一个成员方法
public void show() {
// System.out.println(num);//外部类的成员变量没有加入static修饰
System.out.println(num2);
}
public static void show2() {
// System.out.println(num);//外部类的成员变量没有加入static修饰
System.out.println(num2);
}
}
}
public class InnerClassDemo4 {
public static void main(String[] args) {
//静态的成员内部类中成员的访问方式
//外部类名.内部类名 对象名=new 外部类名.内部类名();
Outer4.Inner4 p=new Outer4.Inner4(); //类上Inner4此时就相当于外部类的静态成员方法
p.show2();
p.show();
System.out.println("-----------");
//对于show()2是内部类的静态的成员方法
Outer4.Inner4.show2();
}
}