java59-static修饰内部类

class Outer {
private int num = 10;
private static int num2 = 100;

 //内部类用静态修饰是因为内部类可以看出是外部类的成员
 public static class Inner {
      public void show() {
          //System.out.println(num);
         System.out.println(num2);
     }

     public static void show2() {
         //System.out.println(num);
         System.out.println(num2);
     }        
 }

}

class InnerClassDemo4 {
public static void main(String[] args) {
//使用内部类
// 限定的新静态类
//Outer.Inner oi = new Outer().new Inner();
//oi.show();
//oi.show2();

     //成员内部类被静态修饰后的访问方式是:
     //格式:外部类名.内部类名 对象名 = new 外部类名.内部类名();
     Outer.Inner oi = new Outer.Inner();
     oi.show();
     oi.show2();
     
     //show2()的另一种调用方式
    Outer.Inner.show2();
 }

 

posted @ 2022-06-22 22:55  前端导师歌谣  阅读(54)  评论(0)    收藏  举报