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


Please Help Members By Posting Answers For Below Questions

What is the interface in c#?

607


what is the difference between a struct and a class in c#?

656


Name which controls do not have events?

639


How are Windows programs different from normal C-programs?

1770


Is c# a strongly-typed language?

626






What is the difference between interface and inheritance in c#?

552


windows c# using datagridview in edit form sql server

3690


How to implement delegates in c#.net

640


How do you serialize in c#?

548


What are circular references?

600


Are c# tuples immutable?

584


Is c# and c sharp same?

550


What is the usage of OLE?

666


What are events in C#?

640


What is the base class in .net from which all the classes are derived from?

586