Click here to Skip to main content
15,891,774 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
can you allow class to be inherited but method not overridden

C#
class abc
{

   public virtual void a()
    {
    }
}
class pqr:abc
{
    public override void a()
    {
    }
}


how to protect a() to override by child class
Posted
Updated 3-May-14 3:19am
v2
Comments
[no name] 3-May-14 8:39am    
yes
Emre Ataseven 3-May-14 11:03am    
So why is it virtual?

 
Share this answer
 
Comments
Maciej Los 3-May-14 9:02am    
+5
 
Share this answer
 
Comments
Maciej Los 3-May-14 9:02am    
+5
José Amílcar Casimiro 3-May-14 13:17pm    
Thx
The second edition of your question totally differs from first one.

I'd suggest you to read this: Inheritance and Derived Classes[^].

Quote:
The base method, which is to be overridden, must be declared as virtual, abstract, or override: it is not possible to override a non-virtual or static method in this way.


Further information:
10.2.5 Static and instance members[^]
 
Share this answer
 
v2
Comments
Peter Leow 3-May-14 10:12am    
+5!
Maciej Los 3-May-14 10:23am    
Thank you, Peter ;)
José Amílcar Casimiro 3-May-14 13:17pm    
+5
Maciej Los 3-May-14 13:56pm    
Thank you, Jose ;)
Member-515487 5-May-14 4:25am    
not understood can base class method sealed
public sealed virtual void a()
{
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900