如何继承构造函数从超类到子类 [英] how to inherit Constructor from super class to sub class

查看:165
本文介绍了如何继承构造函数从超类到子类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将构造函数从超类继承到子类?

How to inherit the constructor from a super class to a sub class?

推荐答案

构造函数不会继承,

这是一个如何工作的例子:

Here is an example of how this works:

class Foo {
    Foo(String str) { }
}

class Bar extends Foo {
    Bar(String str) {
        // Here I am explicitly calling the superclass 
        // constructor - since constructors are not inherited
        // you must chain them like this.
        super(str);
    }
}

这篇关于如何继承构造函数从超类到子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆