1.子类覆盖父类的成员变量
class A{ String name = "tom"; A(String name){ this.name = name; } } class B extends A{ String name = "jack"; B(String name){ super(name); } } public class BigInt { public static void main(String[] args) { B b = new B("helen"); System.out.println(b.name); } }
运行结果:
jack
---------------------------------------------------------------------------------------------------------------------------------------
class A{ String name = "tom"; A(String name){ this.name = name; } } class B extends A{ String name = "jack"; B(String name){ super(name); } } public class BigInt { public static void main(String[] args) { A b = new B("helen"); System.out.println(b.name); } }
运行结果:
helen
---------------------------------------------------------------------------------------------------------------------------------------
class A{ String name = "tom"; A(String name){ this.name = name; } } class B extends A{ String name = "jack"; B(String name){ super(name); this.name = name; } } public class BigInt { public static void main(String[] args) { A b = new B("helen"); System.out.println(b.name); } }
运行结果:
helen
---------------------------------------------------------------------------------------------------------------------------------------
class A{ String name = "tom"; A(String name){ this.name = name; } } class B extends A{ String name = "jack"; B(String name){ super(name); this.name = name; } } public class BigInt { public static void main(String[] args) { B b = new B("helen"); System.out.println(b.name); } }
运行结果:
helen