简体   繁体   中英

Access variable from a different class in a different package?

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
    }

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 (ie 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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM