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
Give an example where we have to specifically use C programming language and C++ programming language cannot be used?
How to improve object oriented design skills?
Get me an image implementation program.
Why it is called runtime polymorphism?
What are the benefits of oop?
Write a c++ program to display pass and fail for three student using static member function
What is meant by multiple inheritance?
to find out the minimum of two integer number of two different classes using friend function
What are properties in oop?
class CTest { public: void someMethod() { int nCount = 0; cout << "This is some method --> " << nCount; } }; int main() { CTest *pctest; pctest->someMethod(); return 0; } It will executes the someMethod() and displays the value too. how is it possible with our creating memory for the class . i think iam not creating object for the class. Thanks in Advance... Prakash
What is the real life example of polymorphism?
What does it mean when someone says I oop?
What is abstraction in oop?
Can we define a class within the interface?
What is constructor in oop?