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 interface in c#?
what is the difference between a struct and a class in c#?
Name which controls do not have events?
How are Windows programs different from normal C-programs?
Is c# a strongly-typed language?
What is the difference between interface and inheritance in c#?
windows c# using datagridview in edit form sql server
How to implement delegates in c#.net
How do you serialize in c#?
What are circular references?
Are c# tuples immutable?
Is c# and c sharp same?
What is the usage of OLE?
What are events in C#?
What is the base class in .net from which all the classes are derived from?