Can you override private virtual methods?

Answer Posted / vivek

virtual or abstract members cannot be private.

Ex: error occurs during the static compilation phase, which
means that no program that declares a private virtual method
will ever be executed in any way.
C#
class A
{
private virtual int Test()
{
return 1;
}
}

class Program
{
static void Main()
{
}
}

Compile-time error

Error 1
'A.Test()': virtual or abstract members cannot be private

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What sort algorithm does c# use?

491


What are the types of comments in c#?

537


What is form feed and carriage return?

467


What is property in c#?

530


What is expression tree in c#?

468






Can we change static value in c#?

514


What are Types of assemblies that can be created in dotnet

573


What is hashtable c#?

464


How many types of constructors are there in c#?

460


What is the difference between dll and lib?

466


What is the use of base keyword? Tell me a practical example for base keyword’s usage?

526


What is a satellite assembly in c#?

536


What method is used to sort the elements of the array in descending order?

554


Can a private virtual method can be overridden?

549


Explain the various types of classes used in c#?

485