Lessons learned from chores: Be careful and careful when doing things.

Source: Internet
Author: User

Today, I was teased by a friend, so I felt this was the case. A friend sent me a piece of code and asked me about the execution result. The Code is as follows:

Using system;
Using system. Collections. Generic;
Using system. text;

Namespace Test
{
Class Program
{
Static void main (string [] ARGs)
{
Subclass sub = new subclass ();
Console. Readline ();
}
}

Public class baseclass
{
Public baseclass ()
{
Console. writeline ("base class constructor ");
}
}

Public class subclass
{
Public subclass ()
: Base ()
{
Console. writeline ("subclass constructor ");
}
}
}

 

I think it's too small to look at us. I am sorry. net has been tossing for more than three years, so I don't know such basic knowledge. Isn't it a problem about the sequence of calling constructors of the subclass and base classes? Currently, the base class constructor is executed first, and the execution result is naturally:

Base Class Constructor
Subclass Constructor

As a result, I was ridiculed by my friends. Of course, I did not accept it and I argued with it. A friend suggested that I run it for a moment. I thought it was the same. The facts showed everything. So I created a project, copied, pasted, and ran it. Then I was dumpfounded. The result turned out to be:

Subclass Constructor

 

Impossible! Why didn't the base class constructor run? Search online. That's right. The constructors of the base class should be executed first. So in the face of unquestionable theories and equally unquestionable results, I am confused, and I am eager to seek advice. As a result, my friend smiled and said, "Let's take a closer look, does subclass inherit baseclass?"

Let me look at it again!

This bitch gave two class names that were so cheap. As a result, I was not aware of it for a while, but it turned out to be a ship in the gutter.

Shame, deserve to be despised.

Technically, you must be careful and careful when doing things. If you are careful about the difficult technology, you can always learn it. However, no matter how much technology you have learned, if you do not have any basic skills beyond the technology, you may make a low-level mistake that will make you regret.

Zhizhizhizhijie.

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.