黑马程序员技术交流社区

标题: 关于子类的构造函数 [打印本页]

作者: 杨翔    时间: 2013-6-15 18:02
标题: 关于子类的构造函数
本帖最后由 杨翔 于 2013-6-16 19:01 编辑

我有一个父类它的构造函数是
    Person(String name, int age)
    {
            this.name = name;
            this.age = age;
    }
父类有一个说话的方法能输出名字和年龄,现在我想有一个子类叫Chinese 怎么写构造方法能在new对象的时候再加入一个country参数?
作者: emos-c    时间: 2013-6-15 18:14
本帖最后由 emos-c 于 2013-6-15 18:25 编辑
  1. Class Chinese extends Person
  2. {
  3. Chiinese(String name, int age,String country)</P>
  4. {
  5. super(name);
  6. super(age);
  7. this.country=country;
  8. }
  9. }
复制代码

作者: ㄗs:/|丶hearts    时间: 2013-6-15 19:05
super(name); super(age);  这样写是错的吧
  1. class Chinese extends Person {
  2.         private String country;
  3.         Music(String name, int age,String country) {
  4.                 super(name, age);
  5.                 // TODO Auto-generated constructor stub
  6.                 this.country = country;
  7.         }
  8.        
  9. }
复制代码

作者: Spole_168    时间: 2013-6-15 21:00
class Chinese extends Person {
        private String country;
        Music(String name, int age,String country) {
                super(name, age);
                this.country = country;
        }
        
}




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2