How to make a class not inheritable other than sealed?

Answers were Sorted based on User's Feedback



How to make a class not inheritable other than sealed?..

Answer / 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

How to make a class not inheritable other than sealed?..

Answer / rasik bihari

I don't agree with this (Answer # 1) as Making the class as
private will prevent it from even being initialized or
instantiated. I don't have the answer myself :-)

Is This Answer Correct ?    0 Yes 0 No

How to make a class not inheritable other than sealed?..

Answer / bikas pandey

Declare The Class Modifier As Private

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More C Sharp Interview Questions

What is the purpose of namespace?

0 Answers  


What do you understand by an Implicit Variable?

0 Answers   CGI,


Why we use get and set method in c#?

0 Answers  


Is c# an array?

0 Answers  


What is interface inheritance in c#?

0 Answers  


What do you mean by generic class in c#?

0 Answers  


How to reduce image resolution in C#?

0 Answers   IBM,


What is the difference between class and abstract class?

9 Answers  


What is scavenging?

2 Answers   HCL,


What is a decimal c#?

0 Answers  


What is the advantage of generics in c#?

0 Answers  


What is Delegate and what is it used for ?

0 Answers   NA,


Categories