日期:2014-05-20 浏览次数:20669 次
class Father{ String a; String b; Father(String a,String b){ this.a = a; this.b = b; } } class Son extends Father{ String c; Son(String a, String b, String c){ super(a, b); this.c = c; } } public class TestExtend { public static void main(String[] args){ Father f = new Father("木工","修车"); Son s = new Son(f.a,f.b,"音乐"); System.out.println(f.a + " " + f.b); System.out.println(s.a + " " + s.b + " " + s.c); } }
Son s = new Son("木工","修车","音乐");// 还不是一样?
------解决方案--------------------
Father f = new Father("木工","修车"); Son s = new Son(f.a,f.b,"音乐"); System.out.println(f.a + " " + f.b); System.out.println(s.a + " " + s.b + " " + s.c);