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 the data type for bit in c#?
What is the difference between Decorator and Adapter pattern?
What is the benefit of delegate in c#?
What is inheritance in csharp?
What is the use of command builder?
Is c# the same as d flat?
What is difference between arraylist and list in c#?
Illustrate namespaces in c#?
How do I declare inout arguments in c#?
What are the access modifiers in c#?
What are strongly typed objects?
What is collection class c#?
Do loops c#?
How do I stop my console from closing in c#?
Why can’t struct be used instead of class for storing entity?