Here is my code snippet:
public class Test { public static void main(String[] args) { class EnglishHelloThere { int a=10; } } }
I created a local class to find out which access modifier I get when no variable modifier compiles in the local class.
This is what I got in javap
Compiled from "Test.java" class com.Test$1EnglishHelloThere SourceFile: "Test.java" EnclosingMethod: #21.#23 // com.Test.main InnerClasses: #27= #1; //EnglishHelloThere=class com/Test$1EnglishHelloThere minor version: 0 major version: 51 flags: ACC_SUPER Constant pool: #1 = Class #2 // com/Test$1EnglishHelloThere #2 = Utf8 com/Test$1EnglishHelloThere #3 = Class #4 // java/lang/Object #4 = Utf8 java/lang/Object #5 = Utf8 a #6 = Utf8 I #7 = Utf8 <init> #8 = Utf8 ()V #9 = Utf8 Code #10 = Methodref #3.#11 // java/lang/Object."<init>":()V #11 = NameAndType #7:#8 // "<init>":()V #12 = Fieldref #1.#13 // com/Test$1EnglishHelloThere.a:I #13 = NameAndType #5:#6 // a:I #14 = Utf8 LineNumberTable #15 = Utf8 LocalVariableTable #16 = Utf8 this #17 = Utf8 Lcom/Test$1EnglishHelloThere; #18 = Utf8 SourceFile #19 = Utf8 Test.java #20 = Utf8 EnclosingMethod #21 = Class #22 // com/Test #22 = Utf8 com/Test #23 = NameAndType #24:#25 // main:([Ljava/lang/String;)V #24 = Utf8 main #25 = Utf8 ([Ljava/lang/String;)V #26 = Utf8 InnerClasses #27 = Utf8 EnglishHelloThere { int a; flags: com.Test$1EnglishHelloThere(); flags: Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #10 // Method java/lang/Object."<init> ":()V 4: aload_0 5: bipush 10 7: putfield #12 // Field a:I 10: return LineNumberTable: line 12: 0 line 13: 4 line 12: 10 LocalVariableTable: Start Length Slot Name Signature 0 11 0 this Lcom/Test$1EnglishHelloThere; }
So basically the flags field is left blank, so I got confused which access modifier makes this get variable
because if I add private int a=10; or public int a=10; I get
public int a; flags: ACC_PUBLIC
or
protected int a; flags: ACC_PROTECTED
So, what access modifier does by default?
user4822607
source share