Can a base class contain its derived class?

Thursday, June 25, 2009

Can a base class contain its derived class?
Yes. But the reverse is not possible.

using System;
using System.Collections.Generic;
using System.Text;

namespace OppsTest
{
class A
{
int i = 1;

public A()
{
}

public void testa()
{
Console.Out.Write(i);
}
}

class B : A
{
int j = 3;
public B()
{
}

public void testb()
{
Console.Out.Write(j);
}

}




class Program
{
static void Main(string[] args)
{
A a = new B();
a.testa();
Console.In.Read();
}
}
}

0 comments

Post a Comment

LinkWithin

Blog Widget by LinkWithin

Recommended Books