Possible Duplicate: In Java, what's the difference between public, default, protected, and private? Why can't a subclass in one package access the protected member of it's superclass (in another package) by the reference of the superclass? I am struggling with this point. Please help me package points; public class Point { protected int x, y; } package threePoint; import poi
可能重复: 在Java中,public,default,protected和private有什么区别? 为什么一个包中的子类不能通过超类的引用访问其超类的保护成员(在另一个包中)? 我正在为这一点而努力。 请帮帮我 package points; public class Point { protected int x, y; } package threePoint; import points.Point; public class Point3d extends Point { protected int z; public void delta(Point p) { p.x += this.x;
This question already has an answer here: In Java, difference between package private, public, protected, and private 26 answers For the sake of this explanation, the terms "functions" and "methods" are used interchangably. There is a small difference between them, for more information, ask Google. Methods in Java that do not explicitly specify a modifier are by default
这个问题在这里已经有了答案: 在Java中,封装私有,公共,受保护和私有26个答案之间的区别 为了解释,术语“功能”和“方法”可互换使用。 他们之间有一点点区别,要了解更多信息,请询问Google。 Java中没有明确指定修饰符的方法默认为package-private ,因此该方法对于声明方法的类所在的包中的所有类都可见。 公共函数可以被所有可以访问该类的类调用(即你的整个项目), 私有方法只能在写入方法的类中调用。还有受保
This question already has an answer here: In Java, difference between package private, public, protected, and private 26 answers The public abstract method will be accessible in the other package where as the protected abstract method can not be accessed. Check the example below. An abstract class with both public and protected abstract methods package package1; public abstract class MyC
这个问题在这里已经有了答案: 在Java中,封装私有,公共,受保护和私有26个答案之间的区别 public abstract method将在其他包中被访问,因为被protected abstract method不能被访问。 检查下面的例子。 具有公共和受保护的抽象方法的抽象类 package package1; public abstract class MyClass { abstract protected String method1(); abstract public String method2(); } 另一个扩展类并实现抽象类的包。 packag
This question already has an answer here: In Java, difference between package private, public, protected, and private 26 answers package-private is not a real modifier. You can't type package-private and get the system to recognize it as an access modifier. It's really the default, made by not including any other modifiers. It means that the given members can only be accessed in t
这个问题在这里已经有了答案: 在Java中,封装私有,公共,受保护和私有26个答案之间的区别 package-private不是一个真正的修饰符。 您无法键入package-private并让系统将其识别为访问修饰符。 这真的是默认设置,不包括任何其他修饰符。 这意味着给定的成员只能在同一个包中访问。 例如, com.hexafraction.Cow可以在com.hexafraction.Cow中访问具有默认修饰符(实际上没有)的com.hexafraction.Dog ,但com.foo.Crow
This question already has an answer here: In Java, difference between package private, public, protected, and private 26 answers The constructor you are calling is private. You need to call LocalDate birthDate = LocalDate.of(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day)); to construct your date.
这个问题在这里已经有了答案: 在Java中,封装私有,公共,受保护和私有26个答案之间的区别 你所调用的构造函数是私有的。 你需要打电话 LocalDate birthDate = LocalDate.of(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day)); 去建造你的日期。
This question already has an answer here: In Java, difference between package private, public, protected, and private 26 answers For better understanding you need to see this Access Modifiers Same Class Same Package Subclass Other packages public Y Y Y Y protected Y
这个问题在这里已经有了答案: 在Java中,封装私有,公共,受保护和私有26个答案之间的区别 为了更好地理解你需要看到这个 Access Modifiers Same Class Same Package Subclass Other packages public Y Y Y Y protected Y Y Y N no acces
This question already has an answer here: In Java, difference between package private, public, protected, and private 26 answers The implicit access level of a manually declared field in an enum is package-private , exactly the same as it in normal classes. Thus your sound field will be accessible if and only if Animals and TestEnum are in the same package. I tried to find a solid quote fo
这个问题在这里已经有了答案: 在Java中,封装私有,公共,受保护和私有26个答案之间的区别 enum中手动声明字段的隐式访问级别是package-private ,与普通类中的完全相同。 因此,只有当Animals和TestEnum在同一个包中时,您的sound场才可以访问。 我试图在JLS中为此找到一个坚实的引用,但不幸的是,枚举规则分散在整个地方,规定为正常类的规则的例外,因此必须从片断中组合规则。 JLS§6.6.1确定可访问性说: 只有类
This question already has an answer here: In Java, difference between package private, public, protected, and private 26 answers You should follow the Principle of Least Privilege. This means that members should be assigned the minimum accessibility needed for the program to work. If an unrelated class needs access, make it public . Typically this is done only for methods that provide ma
这个问题在这里已经有了答案: 在Java中,封装私有,公共,受保护和私有26个答案之间的区别 你应该遵循最低特权原则。 这意味着应为成员分配程序工作所需的最小可访问性。 如果一个不相关的类需要访问,请将其public 。 通常,这只对提供对数据的托管访问的方法来完成。 如果要完全信任子类来操作数据,并且它需要它正常工作,则可以使该成员protected 。 否则,将其设为private ,所以没有其他类可以访问它(不需
This question already has an answer here: In Java, difference between package private, public, protected, and private 26 answers protected modifier is used only with in the package and in sub-classes outside the package. When you create a object using Example ex=new Example(); it will call parent class constructor by default. As parent class constructor being protected you are getting a c
这个问题在这里已经有了答案: 在Java中,封装私有,公共,受保护和私有26个答案之间的区别 受保护的修饰符仅用于包和包外的子类中。 当你使用Example ex=new Example();创建一个对象时Example ex=new Example(); 它会默认调用父类构造函数。 作为受保护的父类构造函数,您将收到编译时错误。 您需要根据JSL 6.6.2.2调用受保护的构造函数,如以下示例2中所示。 package Super; public class SuperConstructorCall {
What is the difference in the accessibility of the following variables in Java? public class Joe { public int a; protected int b; private int b; int c; } I'm most interested in what the last one is doing. public: read/writable for anyone protected: read/writable for instances of subclasses and from within the enclosing package private: read/writable for any instance of
Java中以下变量的可访问性有什么区别? public class Joe { public int a; protected int b; private int b; int c; } 我最感兴趣的是最后一个人在做什么。 公共:任何人都可以读/写 保护:对于子类的实例和封装包内的读/写 private:对于类的任何实例以及内部或外部(封闭)实例的读/写 int c:package-private,对于同一个包内的所有类,读/写 有关更多详细信息,请参阅JLS 编辑:添加评论保护