Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am working in a project and i want to stop the class being inherited..
Posted
Comments
Sergey Alexandrovich Kryukov 2-Jan-13 23:22pm    
Please: 1) stop posting non-question in this forum, called "Quick Questions & Answers", 2) do not post your comments and other text as "solutions".

Doing so can hardly help you, but may only cause some down-votes and abuse reports, unpleasant things you don't want.

—SA

Mark it as sealed[^]

C#
public sealed class myClass : myBase {...}
 
Share this answer
 
Comments
__TR__ 31-Dec-12 4:59am    
This answer doesn't deserve a 1. Countered.
Sergey Alexandrovich Kryukov 2-Jan-13 23:23pm    
Agree, a 5.
—SA
fjdiewornncalwe 9-Jan-13 16:07pm    
+5. Of course.
by putting "Sealed" keyword, you can achieve your target. sealed keyword do not let any class to be inherited by other class.
I would also suggest you to please first learn access specifiers and then do start programming other wise, you structure will begun dangling at some place.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 2-Jan-13 23:25pm    
Your second clause is really valuable. But the first one is merely a mistake. You make class concrete it it is non-abstract. Sealed is not related to concreteness/abstractness.
—SA
Faisalabadians 3-Jan-13 1:22am    
I said concrete in sense of c++, there is the concept for concrete instead of sealed. I know, it should not be said.
You can create it as Sealed class. Sealed class cannot be inherited.
Ex.
public sealed class yourClass {..}
 
Share this answer
 
Make it a sealed class when writing the class. sealed a keyword used when you want to just initialize the class and use the object and do not want any other class to inherit it.

For Examples:

C#
public sealed MyClass
{
    //Class members
}
 
Share this answer
 

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



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