package com.test7; public class test7 { public static void main(String[] args) { Son son = new Son(1000, "张三"); /** * 打印显示 Father的构造函数1000 张三 Son的构造函数1000 张三 */ } } class Father { private int userId; private String userName; public Father(int us…
代码 public class Test { public static void main(String[] args) { new Circle(); } } class Draw { public Draw(String type) { System.out.println(type+" draw constructor"); } } class Shape { private Draw draw = new Draw("shape"); public Sha…
代码 public class Test { public static void main(String[] args) { Shape shape = new Circle(); System.out.println(shape.name); shape.printType(); shape.printName(); } } class Shape { public String name = "shape"; public Shape(){ System.out.println(…
当java的子类和父类具有相同名字的属性时,到底java是怎么处理的. 先看代码: package com.joyfulmath.study.field; public class Person { public String name; public String getName() { return name; } } package com.joyfulmath.study.field; public class Student extends Person { public String…
# 看题目是不是很绕,这个我也不知道怎么才能更简单的表达了... # 先看代码: public class Common { public static void main(String[] args) { Sub sub = new Sub(); sub.testSub(); } } class Parent { protected boolean test() { throw new RuntimeException(); } protected void testParent() { if…
super关键字 10.1子父类中构造方法的调用 public class Test { public static void main(String[] args) { new Zi(); } } class Fu{ int num ; Fu(){ System.out.println("Fu构造方法"+num); num = 4; } } class Zi extends Fu{ Zi(){ //super(); 调用父类空参数构造方法 System.out.println(&qu…