本帖最后由 崔维友 于 2012-12-3 17:21 编辑
你的代码中,子类并没有获得传入的值。如例:- class ExtendsDemo
- {
- public static void main(String[] args)
- {
- Children child = new Children("The name");
- System.out.println(child.name);
- }
- }
- class Father
- {
- String name;
- Father(String name)
- {
- this.name=name;
- System.out.println("Father's name : "+this.name);
- }
- }
- class Children extends Father
- {
- String name;
- Children(String childrenname)
- {
- super(childrenname); //直接给了父类,子类没有得到
- System.out.println("Children's name : "+this.name);
- }
- }
复制代码
|