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.