I just started reading a Java book and wondered; which access specifier is the default one, if none is specified?
I just started reading a Java book and wondered; which access specifier is the default one, if none is specified?
default is a keyword that is used as an access modifier for methods and variables.
Using this access modifier will make your class, variable, method or constructor acessible from own class or package, it will be also is set if no access modifier is present.
Access Levels
Modifier Class Package Subclass EveryWhere
public Y Y Y Y
protected Y Y Y N
default Y Y N N
private Y N N N
if you use a default in a interface you will be able to implement a method there like this exemple
public interface Computer {
default void Start() {
throw new UnsupportedOperationException("Error");
}
}
However it will only works from the 8 Java version
There is an access modifier called "default" in JAVA, which allows direct instance creation of that entity only within that package.
Here is a useful link: