How to make a class not inheritable other than sealed?
Answer Posted / lalit pradhan
Hey guys this is practically tested answer:
namespace Test
{
class Program
{
static void Main(string[] args)
{
A a = new A();
a.Method();
//B b = new B();
//b.Method("From B");
C c = new C();
Console.ReadKey();
}
}
class A
{
public void Method()
{
Console.WriteLine("From A");
}
}
static class B : A
{
public void Method(string s)
{
Console.WriteLine(s);
}
//void calculate();
}
class C : B //Here you will notice that B's color is
not highlighted to green when its not inheritable
{
public void Final()
{
Console.WriteLine("I am Final Method");
}
}
}
Enjoy!!!
Lalit Pradhan a.k.a DOTNET Gadhaa
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
what is c# command?
Explain the different types of delegates used in c#.
What are the types of inheritance in c#?
What are the different types of comments in c#?
What does out mean in c#?
Are arrays value types or reference types?
Does main have to be static c#?
Define c# delegate?
Explain 'structure padding'?
What are Regex / regular expressions ?
Explain the use of Mutex in C#?
Is cli same as the clr?
Why do we need nullable types in c#?
What is serialization and deserialization in c# with example?
What are the Types of compatabilities and explain them