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 are the main reasons to use c# language?

0 Answers  


What is an array of arrays called?

0 Answers  


Can you override private virtual methods?

5 Answers  


Can an interface extend a class c#?

0 Answers  


How can we give strong name to assembly? What is satellite assembly?

2 Answers   SMNetserv,






what is the purpose of new keyword while creating an object?

3 Answers  


What is a method signature in c#?

0 Answers  


Why do we use class in c#?

0 Answers  


Write the syntax for catching an exception in c#?

0 Answers  


Name the two classes are required for implementing a windows service?

0 Answers  


What is fcl in c#?

0 Answers  


How do you create user defined data types in c#?

0 Answers  


Categories