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/13 05:17:31

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();
}
}
应该这样写,声明为成员变量,否则只是方法局部变量,出了构造方法,就访问不到了.