public class Customer
{
Public virtual string getfunnystring ()
{
Return "Plain ordinary customer. Kaark! ";
}
public class Samplesarray
{
public static void Main ()
{
Customer cust1=new Nevermore60customer ();
Nevermore60customer Cust2;
Cust1=new Customer ();
Console.WriteLine ("Customer referencing customer.") +cust1.getfunnystring ());
Cust1=new Nevermore60customer ();
Console.WriteLine ("Customer referencing Nevenmore60customer:" +cust1.getfunnystring ());
Cust2=new Nevermore60customer ();
Console.WriteLine ("Nevenmore60customer Referencing" +cust2.getfunnystring ());
}
}
Customer cust1=new Nevermore60customer ();
If overridden: Then, if the declared base class object points to a derived class, then the method of the basic override in the derived class is invoked (as shown above)
If the base class method is hidden: public New string getfunnystring ()
{
return "nevermore60.nevenmore!";
}
Then: Customer cust1=new Nevermore60customer (); At this point, Cust1 is still calling the Getfunnystring method in the base class at the time of the Declaration.
However, this problem does not occur when both declarations and assignments are of the same class.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service