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 |
What is scaffolding in c#?
How do you create user defined data types in c#?
About a class access specifiers and method access specifiers ?
What is datagrid c#?
What is the difference between returning iqueryable vs ienumerable?
Is there any way to access private memebers of an object from another object?
ctype(123.34,integer) - should it throw an error? Why or why not?
What are the Different kinds of methods?
Can you describe iuknown interface in short?
Write the syntax for catching an exception in c#?
What can you do as a .net developer?
Does hashset allow duplicates c#?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)