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

Difference between value and reference type.

699


How does bubble sort work?

673


What is the use of console readkey in c#?

672


What is callback in c#?

653


Differentiate between method overriding from method overloading with its functionality?

725


Tell us something about static linking and dynamic linking?

720


Can a method return multiple values in c#?

625


How do I run a cshtml file?

681


Is c# queue thread safe?

688


explain the features of static/shared classes.

688


Why do we use threads in c#?

735


What are the differences between a class and a struct?

702


Why delegates are type safe in c#?

691


What is virtual class in C#?

739


What do u mean by delegation of authority?

719