How can you prevent classes to be inherited?
Answers were Sorted based on User's Feedback
Answer / vijay sharma
We can prevent classes to be inherited by marking the
classes as sealed.
| Is This Answer Correct ? | 24 Yes | 0 No |
Answer / nitin kumar tomar
just make the class sealed like
sealed public class classname
| Is This Answer Correct ? | 6 Yes | 0 No |
Answer / chvramana
Using Keyword Sealed. You can created Sealed class and
You can prevent the class to be inherited.
| Is This Answer Correct ? | 6 Yes | 0 No |
Answer / dhiraj kumar pandey
We can prevent classes to be inherited by using the key
word SEALED.
| Is This Answer Correct ? | 5 Yes | 0 No |
sealed modifier is used for preventing the accident
inhritance of a class. A sealed class can not be inhrited.
Example :
using system;
sealed class abc
{
protected string str = "";
public virtual void hello()
{
str = " Hi i am not in C#";
}
class xyz : abc //--ERROR--
{
public override void hell0()
{
str = "hi i am in C#";
Console.WriteLine("{0}",str);
}
}
class mainclass
{
public static void Main()
{
xyz x = new xyz();
x.hello();
}
}
Note-> if we run above program thn we will get an error
because we inheit class abc while it is sealed.
| Is This Answer Correct ? | 4 Yes | 0 No |
Answer / dhara
we can prevent class to be inherite by making sealed class
by using keyword sealed.
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / nagesh rajarapu
by using sealed keyword before the class name
| Is This Answer Correct ? | 0 Yes | 0 No |
What are variables in c#?
What are c# i/o classes?
Are arrays immutable c#?
i want display a given number into Rupees Format Like Given number is : 156735 my Expected output is 1,56,735. how to display?
Explain what are three test cases you should go through in unit testing?
Can you prevent your class from being inherited and becoming a base class for some other classes?
How can I get around scope problems in a try/catch?
Is java better than c#?
What is the lock statement in c#?
What does void mean in c#?
What are the steps to create a webservice and consume it?
What is the use of oops in 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)