Wednesday, September 9, 2009

Inheritance

public class A

{

public void Afun(string msg)

{

Console.WriteLine("Class A : {0}", msg);

}

}

public class B : A

{

public void Bfun(string msg)

{

Console.WriteLine("Class B : {0}", msg);

}

}

static void Main (string[] args)

{

A objAB = new B();

objAB.Afun("objAB");

//objAB.Bfun(); Class A does not contain a definition for Bfun()
//B objBA = new A();An exception conversion exists

//B objBA = (B)new A();it's compile but not run

A objA = new A();

objA.Afun("objA");

B objB = new B();

objB.Afun("Inheritance");

objB.Bfun("Inheritance");

}

No comments:

Post a Comment