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
How many kinds of elements an array can have?
can you create a function in c# which can accept varying number of arguments
Is c sharp and c# are same?
What is the difference between method and constructor in c#?
How can we make a thread sleep for infinite period ?
What is gridview c#?
What is executescalar in c#?
What is difference between overloading and short circuiting?
What do you mean by generic class in c#?
Can abstract class be sealed?
Can a private virtual method can be overridden?
Can non-default constructors be used with single call sao?
Define thread? Explain about multithreading?
Where do I put dll files?
Is string primitive?