What is the difference between access specifiers and access modifiers?

后端 未结 10 763
我在风中等你
我在风中等你 2020-12-13 02:02

In Java, are access specifiers and access modifiers the same thing?

10条回答
  •  失恋的感觉
    2020-12-13 02:34

    In some older languages public, private, protected and default like C++ are considered as access specifiers and everything else is considered as access modifier but in Java there is no terminology for specifier, everything is by default considered as modifier only. So public, private, protected, default, final, abstract, static, strictfp, synchronized, native, transient and volatile are all modifiers only.

    Simple test for it is when we compile the following code

    private class Test{ }

    we will get compile time error saying that modifier private not allowed here. This is true for other modifiers also. Maybe java compiler (javac) sees everything as a "modifier" only.

提交回复
热议问题