Thursday, December 16, 2010

Abstract Class



Loading




Abstract Class declares functions, derived classes can provide another dfn, for this functions.

we cannot creates objects for abstract class. An abstract class may contain non abstract methods

Here is an Example

abstract class Myabs
{
public abstract void show();
public void hello()
{
Console.WriteLine("Hello");

}
}


class myclass : Myabs
{
string name;


public override void show()
{
Console.WriteLine("Enter Name");
name = Console.ReadLine();
Console.WriteLine("Welcome " + name);
}

public void myownmethod()
{
Console.WriteLine("my method invoked " );
}
}




class Program
{

static void Main(string[] args)
{
myclass m = new myclass();
Myabs ab;
ab = new myclass();
m.show();
m.hello();
Console.Read();

}
}

here note that Myabs 's object ab can access all the methods in it's own class but none of the methods in myclass.

0 comments:

Post a Comment