Java: protected access across packages

I would like to understand what's happening in the example below (where a protected member is being accessed from outside the package through a subclass). I know for classes outside the package, the subclass can see the protected member only through inheritance. There are two packages: package1 and package2 . package1 : ProtectedClass.java package org.test.package1; public class Prote

Java:跨包的受保护访问

我想了解下面的示例中发生了什么(通过子类从包外部访问受保护成员的位置)。 我知道包之外的类,子类只能通过继承来看到受保护的成员。 有两个软件包: package1和package2 。 package1 : ProtectedClass.java package org.test.package1; public class ProtectedClass { protected void foo () { System.out.println("foo"); } } package2 : ExtendsprotectedClass.java package org.test.package

Why the protected modifier behave differently here in Java subclass?

I have the following two class in two different packages. my access modifier for instance method is protected which means any subclass in same or different package has access to it right?. however, in Eclipse I see the following message on my subclass Cat on line 17 The method testInstanceMethod() from the type Animal is not visible My code for super and subclass are below. package inherita

为什么受保护的修饰符在Java子类中的行为有所不同?

我有两个不同的包中有两个类。 我的访问修饰符的实例方法是受保护的,这意味着在相同或不同包中的任何子类都有权访问它? 不过,在Eclipse中,我在第17行的子类Cat上看到以下消息 The method testInstanceMethod() from the type Animal is not visible 我的超级和子类代码如下。 package inheritance; public class Animal { public static void testClassMethod() { System.out.println("The class" + " me

Split 1d array into chunks

I am trying to not load my entire tile based map into memory to save RAM client side. The map will be huge and already is requriring 1GB client side (multi-layered map). I have gotten some perspective on Game Dev SO. I am trying to Load zones/chunks of my game map into memory (ie 300x300) and then when the player moves 100 steps shift the array and load 100 new tiles depending on direction.

将1d数组拆分为块

我试图不把我的整个瓷砖基地图加载到内存中以保存RAM客户端。 该地图将是巨大的,并且已经占用1GB客户端(多层地图)。 我对Game Dev SO有了一些了解。 我试图将我的游戏地图的区域/块加载到内存中(例如300x300),然后当玩家移动100步时移动阵列并根据方向加载100个新的瓦片。 我试图在这个缩放版本上工作,现在有一个通用的问题。 当玩家X / Y坐标位于地图的边界上时(这会导致地图块在地图外),我需要帮助, 这是

Improving the algorithm for removal of element

Problem Given a string s and m queries. For each query delete the K -th occurrence of a character x . For example: abcdbcaab 5 2 a 1 c 1 d 3 b 2 a Ans abbc My approach I am using BIT tree for update operation. Code: for (int i = 0; i < ss.length(); i++) { char cc = ss.charAt(i); freq[cc-97] += 1; if (max < freq[cc-97]) max = freq[cc-97]; dp[cc-97][freq[cc-97]]

改进去除元素的算法

问题 给定一个字符串s和m查询。 对于每个查询,删除字符x第K次出现。 例如: abcdbcaab 5 2 a 1 c 1 d 3 b 2 a Ans abbc 我的方法 我正在使用BIT树进行更新操作。 码: for (int i = 0; i < ss.length(); i++) { char cc = ss.charAt(i); freq[cc-97] += 1; if (max < freq[cc-97]) max = freq[cc-97]; dp[cc-97][freq[cc-97]] = i; // Counting the Frequency } BIT = new

Ruby vs Java: Why world is going to end faster with Java?

I have tested recursive method execution speed with classic example of Honoi Tower. First in Java than JRuby and Ruby with different no. of plates: package com.example; public class Hanoi { public static void main(String[] args) { int [] plates = {25, 26, 27, 28, 29, 30, 31, 32}; for(int i = 0; i < plates.length; i++){ long start = System.currentTimeMillis();

Ruby vs Java:为什么Java会让世界变得更快?

我用Honoi Tower的经典例子测试了递归方法的执行速度。 首先在Java中比JRuby和Ruby不同。 板块: package com.example; public class Hanoi { public static void main(String[] args) { int [] plates = {25, 26, 27, 28, 29, 30, 31, 32}; for(int i = 0; i < plates.length; i++){ long start = System.currentTimeMillis(); doTowers(plates[i], 'A', 'B', 'C'); System.ou

Docker: Which approach is better? WAR embedded in image or base image + war?

Just started playing around with Docker. To deploy a war on tomcat there seem to be two approaches: Create image with java + tomcat + war embedded in the image Have a base image with java + tomcat and then "inject" the war into the base image (through host volume mount, for example) Approach 1: Need to create one image for each build Completely bundled solution Due to the l

Docker:哪种方法更好? WAR嵌入在图像或基础图像+战争?

刚开始玩Docker。 在tomcat上部署一场战争似乎有两种方法: 用图像中嵌入的java + tomcat + war创建图像 用java + tomcat创建一个基础映像,然后将战争“注入”基本映像(例如,通过主机卷装载) 方法1: 需要为每个构建创建一个图像 完全捆绑的解决方案 由于图像尺寸较大,为每个构建维护一个图像并共享下游部署的图像可能成为一个问题 方法2: 在码头集线器中保留一个基础镜像 外部添加战争并运行 较小的可

declaringn a variable in java class (private,static,final)

This question already has an answer here: In Java, difference between package private, public, protected, and private 26 answers private means it can be accessed only by instances of class foo . public means it can be accessed from any object owning a reference to an instance of Class foo . static means it belongs to the class and thus, it's shared by all foo instances. final means

在java类中声明一个变量(private,static,final)

这个问题在这里已经有了答案: 在Java中,封装私有,公共,受保护和私有26个答案之间的区别 private意味着它只能由foo类的实例访问。 public意味着它可以从拥有对foo实例的引用的任何对象访问。 static意味着它属于这个类,因此它被所有foo实例共享。 final意味着它不能改变它的初始值。 final属性一旦初始化就不能修改。 可以修改static属性,但请记住新值由所有实例共享。 private属性只能由foo实例本身修改。

protected references in Java

This question already has an answer here: Understanding java's protected modifier 6 answers In Java, difference between package private, public, protected, and private 26 answers A protected member can be accessed in a subclass outside the package only through inheritance. Try this instead : public class C extends A { void foo() { int b = i; } } There are no needs t

Java中受保护的引用

这个问题在这里已经有了答案: 了解java的protected修饰符6个答案 在Java中,封装私有,公共,受保护和私有26个答案之间的区别 protected成员只能通过继承在包外的子类中访问。 试试这个: public class C extends A { void foo() { int b = i; } } 每次都没有必要参考。 我认为你不了解遗传。 public class B extends A { void foo() { // A a = new A(); No need to instantiate it h

I can access a protected field outside of class in java

This question already has an answer here: In Java, difference between package private, public, protected, and private 26 answers protected variables and methods are accessible from other classes of the same package as well as subclasses of the current class. private variables and method are only accessible from within the current class. If there is no modifier (none of protected , private

我可以在java的类之外访问受保护的字段

这个问题在这里已经有了答案: 在Java中,封装私有,公共,受保护和私有26个答案之间的区别 protected变量和方法可以从同一个包的其他类以及当前类的子类访问。 private变量和方法只能从当前类中访问。 如果没有修饰符(没有protected , private或public ),那么默认情况下,该变量可以从同一包中的任何类访问,但不能从子类访问。 看到这里的官方文件 Java中protected成员对包中的其他类也是可见的。 将你的mai

What is the difference between public void and void methods?

This question already has an answer here: In Java, difference between package private, public, protected, and private 26 answers This has already been answered here: In Java, difference between default, public, protected, and private Without specification of an access modifier the access is determined by the classes location within the package hierarchy. Similar to public, but not the same

公共无效和无效方法有什么区别?

这个问题在这里已经有了答案: 在Java中,封装私有,公共,受保护和私有26个答案之间的区别 这已经在这里得到了解答:在Java中,默认,公共,受保护和私有之间的区别 如果没有指定访问修饰符,则访问由包层次结构中的类位置确定。 与公众类似,但不以任何方式。 对于public void ,“public”这个词不是返回类型。 public是Java中的访问修饰符。 下表显示了每个修饰符所允许的成员访问权限; 有四个 public (none / bl