简体   繁体   中英

Why can't i have an access specifier in a method local Inner class?

Why Method Local Inner class cannot be public? I know it is useless to make them private but why not public? Is that because Method Local Inner is also treated as local variables? As local variables cannot be public. Am i going right or missing something?

public class OuterClass {
   public void outerMethod() {
   public class Inner {  // having problem here
    ... 
    }
  }
 }

Since it is declared within the method body, ie. it's a local class, you can't refer to it by name anywhere else in your code, only in the method body itself following its declaration. It is therefore pointless for it to have an access modifier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM