Can you override private virtual methods?
Answers were Sorted based on User's Feedback
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 |
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 |
Is arraylist generic in c#?
Can we maintain state in webservice?
What is difference between C# and VB.NET?
What is the use of protected in c#?
Can we create multiple constructors?
If we inherit a class do the private variables also get inherited ?
How do you pronounce c#?
How is lazy loading achieved?
What is yield return in c#?
How would you describe encapsulation in c#?
can it possible to acees the virthual method using the override method object? plz give me the example
What is the file extension for c#?