请指出此简单JAVA程序错误在哪里?谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/25 17:45:35
class Father
{private int money;
float weight,height;
String head;
void speak(String s)
{System.out.println(s);
}
}
class Son extends Father
{String hand,foot;
}
public class Example4_15
{public static void main (String args[])
Son boy;
boy=new Son();
boy.weight=1.80f;
boy.height=120f;
boy.head="one head";
boy.hand="two hands";
boy.foot="two foots";
boy.speak=("i am your son");
System.out.println(boy.hand+boy.foot+boy.head+boy.weight+boy.height);
}
}
运行之后出现一堆错误 我真不晓得到底错在哪里。

主方法少了一个大括号 还有调用boy.speak(); 方法的时候多写了一个"="

修改如下

class Father {
private int money;

float weight, height;

String head;

void speak(String s) {
System.out.println(s);
}
}

class Son extends Father {
String hand, foot;
}

public class Example4_15 {
public static void main(String args[]) {

Son boy;

boy = new Son();

boy.weight = 1.80f;

boy.height = 120f;

boy.head = "one head";

boy.hand = "two hands";

boy.foot = "two foots";

boy.speak("i am your son");

System.out.println(boy.hand + boy.foot + boy.head + boy.weight
+ boy.height);
}
}

class Son extends Father {
String hand,foot;
String speak;
}

哎 等我做完 keyiro都做出来了。。。速度快。代码一样我就不说了。。