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 is abstraction encapsulation?
Why is static class not inherited?
What is abstraction in oop with example?
Why do we use oops?
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?
What is a class oop?
What does and I oop mean in text?
what's the basic's in dot net
What is encapsulation oop?
Why is abstraction used?
which feature are not hold visual basic of oop?
Plese get me a perfect C++ program for railway/airway reservation with all details.
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?
explain sub-type and sub class? atleast u have differ it into 4 points?
What are classes oop?