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");
}
}老是报错,但不知道怎样修改好
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");
}
}老是报错,但不知道怎样修改好
解决方案 »
- 谁能帮我用SWT写一个简单的聊天程序!要源代码,功能说明在文章内容里写着呢!很急!
- 数值类型提升问题
- 在线求解
- JFrame显示图片问题 。。一个自学者的无奈。。在线等待结果。。。
- 哪位大哥能给个i/o中 复制文件和文件夹的实例
- 晕``我是JAVA初学者,,有什么集成开发环境吗???
- 一个有意思的JAVA问题,还请大家帮帮忙
- 用JB做一个application,会自动生成两个文件,其中一个是***Frame1.java文件,难道所在的界面都要在这里写?
- applet如何在Tomcat下运行
- 高分求解一个正则表达式!急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 图书管理系统界面问题
- JComboBox实现JTable的编辑器
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()
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");
}
}
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");
}
}
应该是这样的~~~~~~~~~~