javaaccess-specifier

What is the default access specifier in Java?


I just started reading a Java book and wondered; which access specifier is the default one, if none is specified?


Solution

  • The default visibility is known as “package-private” (though you can't use this explicitly), which means the field will be accessible from inside the same package to which the class belongs.

    As mdma pointed out, it isn't true for interface members though, for which the default is "public".

    See Java's Access Specifiers