Polymorphism by object?

Posted by Waqar100 under C# on 4/9/2012 | Points: 10 | Views : 780 | Status : [Member] | Replies : 1
Kindly answer only what i asked , dont tell me what is polymorphism by overriding and overloading.

i read somewhere polymorphism can be achieve by objects(objects can have different forms)
I need an example?




Responses

Posted by: Hariinakoti on: 4/9/2012 [Member] Starter | Points: 25

Up
0
Down
Hi waqar,
i think below program is useful to u..

abstract class A
{
public abstract String AbstractFunc(); //must be implemented
and overriden in Derived classes.

public virtual String VirtualFunc() //may Or may not be
implemented Or overriden in Derived classes.
{
return "Defined VirtualFunc() in Base class A.";
}
}

class B : A
{
public override String AbstractFunc()
{
return "Overriden AbstractFunc() in Derived class B.";
}

public override String VirtualFunc()
{
return "Overriden VirtualFunc() in Derived class B.";
}
}

class C: A
{
public override String AbstractFunc()
{
return "Overriden AbstractFunc() in Derived class C.";
}

public new String VirtualFunc()//VirtualFunc() not Overriden.
{
return "new (shadowed) VirtualFunc() in Derived class C.";
}
}

class D : A
{
public override String AbstractFunc()
{
return "Overriden AbstractFunc() in Derived class D.";
}

//No VirtualFunc() implemented from Base class A.
}


Thanks & Regards
Hari

Waqar100, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response