ThatOneGuyInXNA
ThatOneGuyInXNA

Reputation: 111

XNA inheritance issues

Basically here is a simplified version of my problem

public class A()
{
    public int getNum()
    {
        return 5;
    }
}

public class B() : A()
{
    public int getNum()
    {
        return 12;
    }
}

A test = new B();
test.getNum();

I would like the test.getNum() to return twelve but instead the entire getNum function in B is underlined in green. What am I doing wrong?

Upvotes: 0

Views: 165

Answers (1)

TyCobb
TyCobb

Reputation: 9089

Look into inheritance and virtual

public class A
{
    public virtual int getNum()
    {
        return 5;
    }
}

public class B : A
{
    public override int getNum()
    {
        return 12;
    }
}

Upvotes: 3

Related Questions