在我被问到已经提出的问题之前就被叫了出来。请听我说。当我寻找答案时,没有人遇到与我相同的问题。所以我走了。每当我编译代码时,都会收到一条错误消息,指出变量可以从另一个类的方法进行私有访问。我似乎无法弄清楚这个错误是从哪里来的。我重建了代码,但没有成功。因此,我的程序有3个不同的类。问题在于名为Glue的类无法访问所有皮肤类。
glue class
import java.util.Scanner;
import java.util.Random;
public class glue {
public static void main(String [] args) {
Dank_Memes d = new Dank_Memes();
allskins a = new allskins();
Scanner s = new Scanner(System.in);
int money;
String makemoney = "";
int makemoneycounter = 0;
String caseselect = "";
int selection = 0;
String multistring = "";
int multiint;
Random rand = new Random();
do {
System.out.println(d.menue());
selection = s.nextInt();
if (selection == 1) {
int random = rand.nextInt(10);
System.out.println(a.allskins[random]);
}
}while (selection != 4);
}
}
所有皮肤阶层
public class allskins {
private int allskins;
public String[] allskins() {
String[] allskins = {"Karambit | Autotronic",
"Karambit | Black Laminate",
"Karambit | Blue Steel",
"Karambit | Boreal Forest",
"Karambit | Bright Water",
"Karambit | Case Hardened",
"Karambit | Crimson Web",
"Karambit | Damascus Steel",
"Karambit | Doppler",
"Karambit | Fade",
"Karambit | Forest DDPAT",
"Karambit | Freehand",
"Karambit | Gamma Doppler",
"Karambit | Lore",
"Karambit | Marble Fade",
"Karambit | Night",
"Karambit | Rust Coa",
"Karambit | Safari Mesh",
"Karambit | Scorche",
"Karambit | Slaughter",
"Karambit | Stained",
"Karambit | Tiger Tooth",
"Karambit | Urban Masked"};
return allskins;
}
}
dankmemes类(接口)
public class Dank_Memes {
private int dankmemes[];
public String menue() {
return "1) Select a case you would like to open\n" +
"2) All knifes\n" +
"3) Karambit, Shadow Daggers, M9 Bayonet and Bowie\n" +
"4) Flip Knife, Flachion Knife, Bayonet and Huntsman\n" +
"5) Gut Knife and Butterfly Knife\n";
}
}
我收到的错误代码是“ allskins在allskins中具有私有访问权限”
感谢任何能够提供反馈的人。
最佳答案
调用函数
a.allskins()[random]
因为带有
a.allskins
的a.allskins[random]
表示private int allskins
而不是public String[] allskins()
函数返回的数组。a.allskins
这是一个对象,.allskins
表示访问对象a
的成员并使用一些IDE获得帮助并避免强行编写代码