Why can't a top level class be static in Java?

前端 未结 8 1368
礼貌的吻别
礼貌的吻别 2020-12-04 07:30

Can\'t find a satisfactory answer anywhere.

8条回答
  •  情书的邮戳
    2020-12-04 08:03

    Well I guess you dont understand properly if you desire to see a "static" keyword in an outer class.

    In short how are you even going to use the feature of static on an outer class?

    public class Outer
    {
       public static int x = 0 ; 
    
    }
    

    Now you are going to do Outer.x to access the static variable . This would imply that x shares a single value across all objects of Outer.

    Now that we have that away , of what consequence would the static keyword in the Outer class be ? .

提交回复
热议问题