OOP polymorphism and Inheritance essentials

Source: Internet
Author: User

Early binding and polymorphism

    • The signature rules for C # function overloading are judged by the type and number of arguments, not by the name of the function.
    • The function return value is not signed as an overload.
    • Modifiers are not part of a signature, such as static
    • In the same function, multiple parameter names are unique
    • Ref, Out is a reference pass, the memory address of the parameter is passed
    • Params as a parameter key, can only be used for the last parameter of a function
Inherited
    • Cannot prevent subclasses from overriding the base-like signature method
    • An inheritance relationship is a subclass of the same signature method that looks up first, then finds its base class
    • The base keyword is used by C # to call base class functions, variables in subclasses
    • The inheritance relationship is irreversible
    • In addition to constructors and destructors, subclasses inherit some of the base class
    • Custom classes inherit from the object type by default, but these types of C # cannot be inherited:,,, System.ValueType System.Enum System.Delegate System.Array , etc.
    • C # does not support inheriting from multiple classes
    • C # does not support circular inheritance
    • Sub-class objects can be assigned directly to the base class, whereas a strong turn is required
Virtual
    • In C #, a subclass object can be assigned to a base class object, whereas a strong turn is required.
    • The override keyword is used for subclasses overriding the same signature as the base class virtual function
    • Use new and override to override the same signature function of the base class virtual
    • A function of the virtual modifier that can only be executed at run time
    • function is not modified by virtual, it can be determined at compile time whether it is called
Abstract classes and abstract methods
    • Unable to instantiate with newabstract 抽象类
    • abstract 抽象类可以有子类,其子类实现抽象方法后,可被new实例化对象
    • 如声明了abstract 的函数,则必须声明abstract 的类
    • 当override抽象基类,无法修改基类函数的签名
    • abstract函数,无法同时添加static、virtual关键字
    • abstract 类无法被声明为sealed、static类

OOP polymorphism and Inheritance essentials

Related Article

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.