public class Animal {int age,weight;
public Animal(int age,int weight)
{this.age=age;
this.weight=weight;
}
public int getAge()
{return age;
}
    
}class Dog extends Animal{
private String name;
public Dog(int age,int weight,String name)
{super(age,weight);
this.name=name;
}
public String getName()
{return name;
}
public int getWeight()
    {return weight;
    }
public static void main (String[] args) {
    Dog aDog=new Dog("旺财",5,20);
    System.out.println(Dog.getName+"is"+Dog.getAge+"years old,"+"it's"+get.weight+"kg");
    }
}老是报错,但不知道怎样修改好

解决方案 »

  1.   

    public static void main (String[] args) {
      Dog aDog=new Dog("旺财",5,20);
      System.out.println(Dog.getName+"is"+Dog.getAge+"years old,"+"it's"+get.weight+"kg");
      }
    里面的Dog.getName等方法有错误。应为aDog.getName()
      

  2.   


    public class Animal { int age, weight; public Animal(int age, int weight) {
    this.age = age;
    this.weight = weight;
    } public int getAge() {
    return age;
    }}class Dog extends Animal {
    private String name; public Dog(int age, int weight, String name) {
    super(age, weight);
    this.name = name;
    } public String getName() {
    return name;
    } public int getWeight() {
    return weight;
    } public static void main(String[] args) {
    Dog aDog = new Dog(5, 20, "旺财");
    System.out.println(aDog.getName() + "is" + aDog.getAge() + "years old,"
    + "it's" + aDog.getWeight() + "kg");
    }
    }
      

  3.   

    public class Animal {int age,weight;
    public Animal(int age,int weight)
    {
    this.age=age;
        this.weight=weight;
    }
    public int getAge()
    {
    return age;
    }
        
    }class Dog extends Animal{
    private String name;
    public Dog(int age,int weight,String name)
    {
     super(age,weight);
         this.name=name;
    }
    public String getName()

    return name;
    }
    public int getWeight()
      {
       return weight;
      }
    public static void main (String[] args) {
      Dog aDog=new Dog(5,20,"旺财");
      System.out.println(""+aDog.name+"is"+aDog.age+"years old,"+"it's"+aDog.weight+"kg");
      }
    }
    应该是这样的~~~~~~~~~~