Java Package level access

前端 未结 2 1673

I know that class members with default access control can be accessible at package level but i\'m confused about what does package level access actually mean. If default mem

相关标签:
2条回答
  • 2021-01-20 01:03

    You forget to write

    package pkg1; 
    

    for Test2 class.

    It should work now

    0 讨论(0)
  • 2021-01-20 01:09

    Package level access means that only classes that are defined in the same package can access the package level variable. If you have to import Test, then I'm assuming that Test is in a different package and therefore it can't access i.

    For Test2 to access i, define it in the same package as Test1.

    0 讨论(0)
提交回复
热议问题