Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 9108 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > C# > Run Time PolyMorphism Example---2 For Beginner?????? ...
Sabarimahesh

Run Time PolyMorphism Example---2 For Beginner??????

 Code Snippet posted by: Sabarimahesh | Posted on: 5/10/2012 | Category: C# Codes | Views: 827 | Status: [Member] | Points: 40 | Alert Moderator   
Ads

creating an object of Derived class DerivedClass and storing its reference in the reference variable bc of type BaseClass. This is valid in C#.


class Program

{
static void Main(string[] args)
{
Baseclass bc;
bc = new Baseclass();
bc.Show();
bc = new DerivedClass();
bc.Show();
Console.ReadLine();

}

}

class Baseclass
{
public void Show()
{
System.Console.WriteLine("Baseclass::Show");
}
}

class DerivedClass : Baseclass
{
new public void Show()
{
System.Console.WriteLine("DerivedClass::Show");
}
}



Output



Baseclass::Show
Baseclass::Show


bc is a reference of type Baseclass, the function Show() of class Baseclass will be invoked, no matter whom bc refers to.

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/20/2013 1:24:33 AM