面向對象--簡單的靜態內部類

靜態內部類

public class Static {//靜態內部類


public static void main(String[] args) {


//abroad.within in=new   abroad().new within();如果內部類私有這樣是不可以的


         Out.In in = new Out.In();


            in.funprint();

    }


}

class Out {


    private static int age = 12;


     int y=10;


    static class In {
        
        public void funprint() {
            

            System.out.println(age);


// System.out.println(y);//不能對非靜態字段y 進行靜態引用


          //內部類就只能訪問外部類的靜態成員變量,具有侷限性      
        }
      }

     }


/*

輸出結果:12

*/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章