Stop or avoid inheritance

Posted by Waqar100 under C# on 12/15/2010 | Points: 10 | Views : 2030 | Status : [Member] | Replies : 2
How can I avoid inheritance of parent class ,is there any other way except Sealed class?
kindly give me through example..




Responses

Posted by: SurajRane on: 12/16/2010 [Member] Starter | Points: 25

Up
0
Down
No you can not

Waqar100, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Duraikannan on: 12/17/2010 [Member] Starter | Points: 25

Up
0
Down
Sealed class can be used to restruct the inhertance features in C#.Net. when you can define as "sealed" keyword in your class after that class can not be inherited.

Example

sealed class Sample
{
public int Add(int a,int b)
{
return a+b;
}
}

class MainClass
{
public static void Main()
{
MyClass clsMain= new MyClass();
int Res;
Res=clsMain.Add(3,5);
Console.WriteLine("Result of Add Two No", Res);
}
}

If you can specify the inheritance with new class means then will will get error message...
Example :
class MainClass :Sample
{
} //Error.....


Waqar100, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response