How to call a non virtual function in the derived class by
using base class pointer

Answer Posted / annu agrawal

This can be done by using 'base' keyword in C# language. For eg;

An abstract class is coded as follows:

abstract class AbstractDemo
{
public abstract void Habits();

public virtual void hello()
{
Console.WriteLine("Hello DerievedAbstract class,
hello()");
}

public void adddet()
{
Console.WriteLine("Hello Everybody...");
}
}

Then, I have created a derieved class of this class as:

class DerievedAbstract : AbstractDemo
{
public override void Habits()
{
Console.WriteLine("Hello DerievedAbstract class");
}

public override void hello()
{
base.adddet();
Console.WriteLine("Hello() is a function....");
}

new public void adddet()
{
Console.WriteLine("Hello Everybody....derieved
class");
}
}

In the Main() function, the object of Derieved class is
created as:

class classmain
{
public static void Main(string[] args)
{
DerievedAbstract ab = new DerievedAbstract();
ab.Habits();
ab.hello();
Console.ReadLine();
}
}

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is abstraction encapsulation?

749


Why is static class not inherited?

692


What is abstraction in oop with example?

742


Why do we use oops?

672


if i have same function with same number of argument but defined in different files. Now i am adding these two files in a third file and calling this function . which will get called and wht decide the precedence?

2907






What is a class oop?

677


What does and I oop mean in text?

731


what's the basic's in dot net

1815


What is encapsulation oop?

672


Why is abstraction used?

713


which feature are not hold visual basic of oop?

1816


Plese get me a perfect C++ program for railway/airway reservation with all details.

3526


INSTANCE FIELDS DECLARED private ARE ACCESSIBLE BY THE METHODS ONLY.CAN WE CHANGE THE private FIELD OF AN OBJECT IN A METHOD OF SOME OTHER OBJECT OF THE SAME CLASS?

1737


explain sub-type and sub class? atleast u have differ it into 4 points?

1933


What are classes oop?

685