How to make a class not inheritable other than sealed?
Answers were Sorted based on User's Feedback
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 |
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 |
What is Serialization and how do we implement (in real time scenario)
What are cookies in c#?
What are the different types of classes?
Define a partial class?
Are private class-level variables inherited?
5 Answers HCL, Siebel Systems, Visual Soft,
What is Delegate and what is it used for ?
Can you store multiple data types in System.Array?
20 Answers Satyam, Siebel Systems,
What is the default value of guid in c#?
List down the commonly used types of exceptions in .net
What is a console device?
What is the difference between finally and finalize block?
What is the Use Of Interfaces? For example I have a interface as shown below? Interface IMyInterface { public void MyMethod(); } class MyClass : IMyInterface { public void Mymethod() { Some Code } } class Program { static void Main(string[] args) { MyClass obj = new MyClass(); obj.MyMethod(); } } Here What is My Question is? If i remove Interface and run this code, it will executed then what is the Use of the interface? Can any one give me the solution for this Problem? Thanks in Advance!
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)