从不同包中的不同类访问变量? [英] Access variable from a different class in a different package?
本文介绍了从不同包中的不同类访问变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要设置它,以便每个igCharacter的igAS将受igMech中的变量限制. 这是我所拥有的 首先:
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;
}
秒:
package igMech;
class igLimits {
double aSLimit = 2.5
}
推荐答案
我认为您可能想使用public
修饰符(尽管很难说出问题的意思) .您使用的是默认值,它是包专用的(即,不能从包igMech
之外的任何类访问).使用public
意味着可以从任何程序包中看到一个类.
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
}
这篇关于从不同包中的不同类访问变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文