将参数传递给基类构造函数 [英] Passing parameters to the base class constructor

查看:34
本文介绍了将参数传递给基类构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果基类和派生类都有带参数的构造函数,那么我们在哪里将参数传递给基类构造函数?

If the base class and derived class both have their constructors with parameters then where we pass the parameters to the base class constructors?

推荐答案

像这样:

public class DerivedClass : BaseClass
{
    public DerivedClass(int derivedParam, String baseParam):base(baseParam)
    {
    }
}

此处的 base 关键字调用与提供的参数重载匹配的基类构造函数.

The base keyword here calls the base class constructor that matches the provided parameter overload.

这篇关于将参数传递给基类构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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