Is there a difference in terms of access to the fields a and b ?
// X.java package XY; class X { int a; }; // Y.java package XY; class Y { public int b; }; Is there a difference in terms of access to the fields a and b ?
// X.java package XY; class X { int a; }; // Y.java package XY; class Y { public int b; }; The public access public for the class / method / field, etc. - you can apply anywhere. If you do not specify it, then it will be possible to access it only from the class where it is declared and from the entire package .
If a class without a modifier, then the modifiers of its components (methods, fields, etc.) go into the background. The first is the class itself. That is, if the public field is in a class without a modifier, then it cannot be accessed from a subclass or from another package
package . - FlippyThere are several access levels:
default - used when no access modifier is specified. In this case, the variable is available to the class itself where it is listed, to its internal classes and all classes in the same package with it.private - available only to the class itself and its internal classes.protected - available to the class itself, its internal classes and its heirspublic - accessible to everyone and everywheredefault - inner classes cannot be accessed - FlippySource: https://ru.stackoverflow.com/questions/593403/
All Articles