Overloading Overload & overriding override

Source: Internet
Author: User

First talk about object-oriented 3 features

Encapsulation//is implemented primarily by sealed classes, public/protect/private/internal, with different access levels to control

Inheritance//say is derived

Polymorphism//polymorphism is mainly implemented by override and overload

Override & Overload
Overload called overload, override called override;

Overloading a method is happening in the same class!

Overriding is to override a method in a subclass in a parent class.

1.override:

Parent class: Public virtual string ToString () {return "a";}
Subclass: public override string ToString () {return ' B ';}

In general, when the parent class only provides virtual methods, but the method is used incomplete, or there is no method at all, use the override


2.overload: Available in the same class or in a parent-child relationship class.
public string ToString () {return "a";}
public string ToString (int id) {return ID. ToString ();}

For example, multiple constructors in a class, with default, with parameters


Overrides are virtual methods used to override the base class, which provides a new method in the derived class;

Overloading (overload) provides a mechanism by which the same function names are differentiated by different return value types and parameter tables.
=====================================================

The essential difference is that the function features are the same as the functions of the two functions of overriding (override), although the function names of the two functions of the overloaded (overload) are the same, but the function features are different.
function features include the function name, the type and number of arguments.

Overloading Overload & overriding override

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.