class Dice{ public void get(){System.out.println("哈哈");}} class DiceGame{public DiceGame(){Dice dice = new Dice();}public void get1(){dice.get();}}public class b{public static void main(String[] args){}}这个程序提示 b.java:16:错误:找不

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/26 19:51:05
class Dice{ public void get(){System.out.println(
xRJ@U %ō6v%.EZC14Q(VڊTڈZEhL$ 'IƝnfr9sR*dM ^ER:'d03% U3Mj`Osy^ D_yL"_ ~:j]Lp,Q~z(,+2d9A(UvvqU5vƹKz͹PYD«i&ƫfӅ8u`5CD-~ hT/GT i/4q騕¥jǹmޥLz֓Sjf.\oU|ϧvo0֚^e+B/nqWk霷RX1uモ Xu׼$7g](1hvpcY'nWcPkA7L|蕮pŲ2>Yg!ν{p̰qYĔ? oM

class Dice{ public void get(){System.out.println("哈哈");}} class DiceGame{public DiceGame(){Dice dice = new Dice();}public void get1(){dice.get();}}public class b{public static void main(String[] args){}}这个程序提示 b.java:16:错误:找不
class Dice
{
public void get()
{
System.out.println("哈哈");
}
}
class DiceGame
{
public DiceGame(){
Dice dice = new Dice();
}
public void get1()
{
dice.get();
}
}
public class b
{
public static void main(String[] args)
{
}
}
这个程序提示 b.java:16:错误:找不到符号dice.get();麻烦请大虾指导小弟下到底那里错误 最好能修改成正确的程序

class Dice{ public void get(){System.out.println("哈哈");}} class DiceGame{public DiceGame(){Dice dice = new Dice();}public void get1(){dice.get();}}public class b{public static void main(String[] args){}}这个程序提示 b.java:16:错误:找不
class DiceGame
{
Dice dice;
public DiceGame(){
dice = new Dice();
}
public void get1()
{
dice.get();
}
}
应该这样写,声明为成员变量,否则只是方法局部变量,出了构造方法,就访问不到了.