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 the difference between inheritance and polymorphism?
Write a program to compute for numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the following format: Each line contains a student's first name, then one space, then ten quiz scores all on one line. The quiz scores are in whole number and are separated by one space. Your program will take it input from this file and sends it output to a second file. The data in the output file will be exactly the same as the data in the input file except that there will be one additional number (of type double) at the end of each line. This number will be the average of the student's ten quiz scores. Use at least one function that has file streams as all or some of its arguments.
Explain the advantages of inheritance.
c++ program to swap the objects of two different classes
What are the important components of cohesion?
Why do we use encapsulation in oops?
Plese get me a perfect C++ program for railway/airway reservation with all details.
How does polymorphism work?
Why do we use oops?
What is the point of polymorphism?
What is the types of inheritance?
What are objects in oop?
Why polymorphism is used in oops?
What is the example of polymorphism?
Why can't we have instance(stack) of a class as a member of the same class like eg.Class A{A obj;} as we can have self refential pointer