"Inheritance increases the functionality of a base class by adding additional features to its derived class."

This is a direct statement from my text book's true/false question section. This is given as false and I know this is false but still I don't understand fully why.

Any explanations would be useful.

Thanks.. :)

They could say it is false because the base class is not modified.
It does not add functionality to the base class; it adds functionality to the class inheriting from the base class.

They could say it is false because the base class is not modified.
It does not add functionality to the base class; it adds functionality to the class inheriting from the base class.

Read the statement again:

"Inheritance increases the functionality of a base class by adding additional features to its derived class."

You can use inheritance to add features to a derived class, but there are other possibilities.

Do nothing (not very useful, but legal):

class Base
{
    public void DoSomething()
    {
        // insert code here
    }
}

class Derived : Base
{
}

Change behavior:

class Base
{
    virtual public void DoSomething()
    {
        // insert code here
    }
}

class Derived : Base
{
    override public void DoSomething()
    {
        // different code here
    }
}

You can actually remove functionality:

class Base
{
    public void DoSomething()
    {
        // insert code here
    }
}

class Derived : Base
{
    new public void DoSomething() { }
}

Read the statement again:

You're right, @gusano79.
I was looking for the trick and got tricked. :)

Thanks. I have a much more clearer idea now of whats up with inheritance. I was just wondering why do we use the "new" keyword? For example:

abstract class A
{
public abstract void method1();
public virtual void method2(){}
}

class B : A
{
public override void method2()
{
//code
}
//Why and when should I use the new keyword here? Also what does new keyword do?
//Can I use new keyword with the abstract class?
public new void method2()
{
//code
}
}

//Can I use new keyword with the abstract class?

no you can't create an instance of them.Instead, you have to subclass them and create an instance of your subclass.

Kinda like what you did

Edited 4 Years Ago by zeroliken: n/a

Hey Dudes

I think that statement is true Because It add the dynamic method binding functionality to the base class by adding additional features to derived class

This article has been dead for over six months. Start a new discussion instead.