Can you override private virtual methods?

Answers were Sorted based on User's Feedback



Can you override private virtual methods?..

Answer / tsahi

You cannot write virtual private methods, let alone override
them. as noted above, a private virtual method will not compile.

Is This Answer Correct ?    8 Yes 0 No

Can you override private virtual methods?..

Answer / dharmendra nonia

No,We can't override the private virtual method because
it private access specifier does not allow to inherit the
private member of a class in a derived class.
Ex:--
-------

using System;
public class ABC
{
private virtual void mm()
{
}

}
public class abc:ABC
{
private override void mm()
{
Console.WriteLine("Hello");
}

}
class d:abc
{
public static void Main()
{
d D=new d();
D.mm();
}
}

Output:-
--------
ae.cs(4,23): error CS0621: 'ABC.mm()' : virtual or abstract
members cannot be
private
ae.cs(11,24): error CS0621: 'abc.mm()' : virtual or
abstract members cannot be
private

Is This Answer Correct ?    6 Yes 0 No

Can you override private virtual methods?..

Answer / swapna

No, we cannot access private methods in inherited classes.
They have to be protected in the base class to allow any
sort of access.

Is This Answer Correct ?    6 Yes 1 No

Can you override private virtual methods?..

Answer / sanjay

We cant override private virtual methods...

Is This Answer Correct ?    6 Yes 2 No

Post New Answer

More C Sharp Interview Questions

What is the use of functional interface?

0 Answers  


Explain the difference between private and shared assembly?

0 Answers  


What is difference between method and function in c#?

0 Answers  


Explain the difference between the debug class and trace class?

0 Answers  


What are cshtml files?

0 Answers  






What is parse method in c#?

0 Answers  


How to use session under class file of APP_Code folder?

0 Answers   ADITI,


What is generic delegates in c#?

0 Answers  


What is method in c#?

0 Answers  


Why do we use readonly in c#?

0 Answers  


How would you describe encapsulation in c#?

0 Answers  


What is the difference between Abstract and Interface?

22 Answers   Agile Software, FER, HCL, Sys Universe,


Categories