[You must know. NET] 17th: pair: Overwrite and overload

Source: Internet
Author: User
Tags abstract bool define abstract

This article describes the following:

What is overwrite, what is overload

The difference between overriding and overloading

Application of covering and overloading in polymorphic properties

1. Introduction

Overwrite (override) with overloading (overload), is the achievement. NET object-oriented polymorphism characteristics, one of the basic technologies, two seemingly similar but in fact not the concept, often brings us a lot of misunderstanding, so it is necessary to discuss the difference between the topic, and more importantly, pay attention to its application in polymorphism.

In the series, we have a bit of the topic of the discussion, this article in the form of a topic to do the in-depth discussion, the relevant content please do the previous article for reference.

2. Understanding Overwrite and overload

Start with an example to understand what is overwrite and what is overload?

Abstract class Base
{
//Definition virtual method
Public virtual void MyFunc ()
{
the

//Parameter list is different, virtual is not sufficient to differentiate between
public virtual void MyFunc (String str)
{
}

//Parameter list is different, the return value is different
public bool MyFunc (string str, int id)
{
Console.WriteLine ("AAA");
return true;         
}

//argument list differs in number of occurrences, or in different parameter types of the same position
public bool MyFunc (int ID, string str)
{
Console.WriteLine ("BBB");
return false;         
}

//generic overload, allow the same argument list
public bool Myfunc<t> (string str, int id)
{
return true;     
}

///define abstract method
Public abstract void Func ();
       

Class Derived:base
{
//Blocking parent class member
public new void MyFunc ()
  {
}

//Overwrite base class member
public override void MyFunc (String str)
{
Accesses the parent class member,
Base, in a subclass. MyFunc (str);
}

//Overwrite base class abstract method
public override void Func ()
{
//implementation Overwrite method
}

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.