C # Advanced Programming

Source: Internet
Author: User

I have been diving in the blog Park for a few years. I have read a lot but I have little to remember. Several yearsProgramAfter the employee's work experience, he began to find that there are indeed a lot of projects, but his own things are almost nothing. Just taking advantage of the company's free time, I bought a few books to read about it. It was just a warm story, and I also had a good look at some basic knowledge that I didn't pay much attention to before. I also hope to provide some help to some new users.

 

The basic knowledge about the abstract class in inheritance that needs to be recorded today

  1. Abstract classes and Abstract Functions

    Abstract classes are defined as abstract keywords. abstract classes cannot be instantiated, and abstract functions are not instantiated. They must be rewritten in non-Abstract Derived classes. Abstract Functions are virtual and do not need to be modified by virtual. If they are used, an error is generated. If a class contains an abstract method, the class must be declared abstract.

  2. Sealing and sealing methods

    Declare the class and method as sealed and express it as sealed. The sealed class cannot be inherited, And the sealed method cannot be overwritten.
    In general, it is most likely to declare sealed: If you want to perform operations on classes, classes, or other classes written by yourself on classes or methods outside the domain, rewriting certain functions will leadCodeChaos. It can also be marked as sealed by commercial crude oil bars or methods to prevent third-party extension in the form of illegal authorization protocols.

  3. Derived classes and constructors
    The execution of the constructor is performed from top to bottom according to the hierarchy until the class to be instantiated by the compiler is reached. In this process, each constructor initializes fields in its own class. Therefore, we try to follow this principle when adding our own constructor.
    The execution sequence of the constructor. The constructors in the base class are always called first. That is to say, if the constructor of a derived class can call any base class method, attribute, and any other member that he can access during execution, because the base class has been constructed, other fields are also initialized.

    Public   Abstract   Class Mybaseabsclass
    {
    Private   String Name;
    Public Mybaseabsclass (){}

    PublicMybaseabsclass (StringName)
    {
    Console. writeline (1);
    This. Name=Name;
    }
    }

    Public   Class Subclass1: mybaseabsclass
    {
    Private   String Referrername;

    Subclass1 (){}

    PublicSubclass1 (StringName)
    :Base(Name)
    {
    Console. writeline (3);
    }

    Public Subclass1 ( String Name, String Referrername)
    : Base (Name)
    {
    Console. writeline ( 2 );
    This . Referrername = Referrername;
    }
    }

 

 

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.