public class TextDog {
public static void main(String[] args) {
Dog d = new Dog();
System.out.println("Dog d's weight is "
+ d.getWeight());
d.setWeight(42);
System.out.println("Dog d's weight is "
+ d.getWeight());
d.setWeight(-42);
System.out.println("Dog d's weight is "
+ d.getWeight());
}
}
Dog d = new Dog();     JAVAC的时候显示 找不到符号 可是我输入和书上得的一样哦

解决方案 »

  1.   

    Dog类没有引入喵~~~`书上的例子?
    也许这个例子是在前面例子的基础上改的呢?看看书上前面点有没有Dog类的例子吧....
      

  2.   

    public   class   TextDog   { 
    public   static   void   main(String[]   args)   { 
    Dog   d   =   new   Dog(); 
    System.out.println("Dog   d's   weight   is   " 
    +   d.getWeight()); 
    d.setWeight(42); 
    System.out.println("Dog   d's   weight   is   " 
    +   d.getWeight()); 
    d.setWeight(-42); 
    System.out.println("Dog   d's   weight   is   " 
    +   d.getWeight()); 


    Dog   d   =   new   Dog();           JAVAC的时候显示   找不到符号   可是我输入和书上得的一样哦请问,java加载时如何认知Dog这东西,显然,你没有引入或者说没有告诉java编译器如何解译这个Dog所以是错的
      

  3.   

    就是说这个代码不全?  它调用另外一个  Dog 是吧
    书上前面还有一个代码
    public class Dog{
    private int weight;
    public int getWeight(){
    return weight;
    }
    public void setWight(int newWeight) {
    if ( newWeight >0) {
    weight = newWeight;
    }
    }
    }
      

  4.   

    是的,你把Dog和TextDog放在一个目录里就可以编译了.如果不一样的包,在写TextDog类前必须用import把它引进来.
      

  5.   

    就是说这个代码不全?     它调用另外一个     Dog   是吧 
    书上前面还有一个代码 
    public   class   Dog{ 
    private   int   weight; 
    public   int   getWeight(){ 
    return   weight; 

    public   void   setWight(int   newWeight)   { 
    if   (   newWeight   > 0)   { 
    weight   =   newWeight; 


    }
    ==============================================================
    这不就完了嘛,你把Dog类先javac了,在去javac 你的TextDog类.
      

  6.   

    可是还是显示 TESTdog d.setWeight(42);   d.setWeight(-42);  找不到符号
    顺便问下 明天早上8点到9点 有没有人在  我有个测试要出道题  我放上来 大家帮我看下
      

  7.   

    public   void   setWight(int   newWeight)   { 
    if   (   newWeight   > 0)   { 
    weight   =   newWeight; 
    你少打了一个字母e
      

  8.   

    你的类名到底是TESTdog还是TextDog?
      

  9.   

     没有引入Dog类,自然会出现楼主说的问题啦
      

  10.   

    你的dog类都没有,肯定不行了,把六楼的代码加上就可以了
      

  11.   

    你把Dog类先javac了,在去javac   你的TextDog类.