子类可以继承父类中的构造函数吗

174次

问题描述:

子类能继承父类的方法而不是状态

推荐答案

2023-10-25 14:13:10

可以的。

class Parent(){public Parent(){System.out.println(" parent 1");}public Parent(String n){System.out.println(" parent 2 "+n);}}class Child extends Parent(){public Parent(){super();System.out.println(" Child 1 ");}public Parent(String n){super(n);System.out.println(" Child 2 "+n);}public Parent(int n){System.out.println(" Child 3 "+n);}}

知道问答相关问答

(c)2008-2025 自学教育网 All Rights Reserved 汕头市灵创科技有限公司
粤ICP备2024240640号-6