Access variable from a different class in a different package?

为君一笑 提交于 2019-12-08 12:07:01

问题


I want to set it so igAS for each igCharacter will be limited by a variable in igMech. Here is what I have first :

    package igCharacters;
    import igMech.*;
    protected class igBrand {
            public double igAS = .77;
    }

second:

    package igMech;
    class igLimits {
            double aSLimit = 2.5
    }

回答1:


I think you might want to use the public modifier (although it's quite hard to tell what you mean from your question). You are using default, which is package-private (i.e. not accessible from any class outside the package igMech). Using public means a class is visible from any package.

package igCharacters;
import igMech.*;
protected class igBrand {
  public double igAS = .77;
}

package igMech;
public class igLimits { // now visible from the igCharacters package
  public double aSLimit = 2.5
}


来源:https://stackoverflow.com/questions/16594052/access-variable-from-a-different-class-in-a-different-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!