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 |
Why do we need collections in c#?
What is thread pooling?
What is a statement c#?
What is difference between private and protected?
These questions were asked me in a technical interview: •If we deploy an application on multiple server (like database server, web server) then, each request should be redirected to proper server, then how you will handle it in your code? •How security pinholes will be handled in an application? •What things should be considered while writing a web application? •How will you do load/performance testing of web application? Which framework you will use for it? •How will you implement a cache for results which require a DB access? Please let me know how to write an web application considering all these points. I am not so much aware of architechural design of web application. Your guidelines will be helpful.
Does unity use c++ or c#?
What is the difference between mobile application and desktop application?
Can you use all access modifiers for all types?
int i,string s, String s1 Which is valuetype which is refrence type.
what is the difference between finally and dispose methods?
What is ildasm.exe used for?
Why do we use reflection in c#?