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
What do you mean by Encapsulation?
What is oops concept with example?
Which language is pure oop?
Why multiple inheritance is not possible?
What is difference between abstraction and encapsulation?
#include
write a program to find 2 power of a 5digit number with out using big int and exponent ?
What is the difference between a constructor and a destructor?
What is a function in oop?
What is a superclass in oop?
What is abstraction with example?
What is constructor in oop?
What is object in oop?
Which is not an object oriented programming language?
What are the types of abstraction?