Wednesday, July 9, 2008

.Net Types of classes

Sealed Class: Class cannot be inherited ie cannot be a base class for other classes
sealed class MyClass
{
}

Abstract Class: Cannot be instantiated, they can only be base classes for other classes.Can contain both abstract and non abstract members.

namespace test
{
abstract class abs
{
public abstract int Mul( int x, int y); //abstract method needs to be overridden in derived class
public int Add( int x, int y)
{
return x+y;
}
}

class c2:abs
{
public override int Mul( int x, int y)
{
return x*y;
}

static void Main( string[] args)
{
c2 xx = new c2();
int z = xx.Add(1,2);
int u = xx.Mul(1,2);
}
}
}

No comments:

Post a Comment