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 the difference between inheritance and polymorphism?

592


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.

2576


Explain the advantages of inheritance.

675


c++ program to swap the objects of two different classes

1765


What are the important components of cohesion?

557






Why do we use encapsulation in oops?

522


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

3429


How does polymorphism work?

635


Why do we use oops?

593


What is the point of polymorphism?

588


What is the types of inheritance?

604


What are objects in oop?

610


Why polymorphism is used in oops?

585


What is the example of polymorphism?

560


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

1621