Monday 13 April 2015

Sealed Class in C# Programming

Hello Friends,
                  Previous Chapter I have described oop concept but now I will expain anther concept i,e.Sealed class in C# dot.Generally it is opposite of abstract class  and  it can't  inherited  because when we will create a class as sealed modifier then it will prevant to inherit from this class.

Suppose class c1 and class c2 are two class if we declare sealed to any class that canot be inherit ,just see that small example in below.

Class c1
{
}
sealed class c2:c1
{

}
Note:Now just see that class c2 inherit from class c1,but at 2nd step we have declaed class c2 as sealed so for that reason there is not possible thatno class can inherit from class c2 if we will do than that fire error.

Ex:

using System;

namespace sealedclass
{
sealed class mysealedclass
{
public void mypro(int i,int j)
{
Console.WriteLine (i+j);
}

}
class sealedprog
{
static void Main()
{
mysealedclass obj = new mysealedclass();
obj.mypro (35,40);
}
}
}



output:
75

Thanks & Regard
Rabi

No comments:

Post a Comment