Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Inheritance 如何从另一个类访问超类方法?_Inheritance - Fatal编程技术网

Inheritance 如何从另一个类访问超类方法?

Inheritance 如何从另一个类访问超类方法?,inheritance,Inheritance,如何从另一个类访问super类方法?我有下面的场景。请帮帮我 class A { void myMethod() { } } class B : A { void myMethod() { } } class C { B b = new B(); // How to acces class A method? } 您可以尝试使用super()函数。在B中,您将声明为: Class B : A { void MyMet

如何从另一个类访问super类方法?我有下面的场景。请帮帮我

class A
{
    void myMethod()
    {
    }
}

class B : A
{
    void myMethod()
    {
    }
}

class C
{
    B b = new B();

    // How to acces class A method?
}

您可以尝试使用super()函数。在B中,您将声明为:

Class B : A {
    void MyMethod() {
        super();
        // Addition code...
    }
}

不能,因为B重写了MyMethod定义。你需要一个实例。< /P>也,<代码> B.myMethod < /> >重写<代码> A.myMethod < /> >还是隐藏它?这个代码是java和C++的奇怪混合。是哪一个?这不是他要的。