Invocation order of base classes and subclasses (C#,java)
Source: Internet
Author: User
Now the idea of OO programming has become more and more accepted, but we are not familiar with some basic things, such as the order of invocation of base classes and subclasses. Here I take C # as an example for you to explain
For a section of code below
public class BaseClass
{
public string a= "BaseClass";
Public BaseClass ()
{
A= "Initialization of BaseClass";
}
}
public class Extendclass:baseclass
{
private string b= "Extendclass";
Public Extendclass (): Base ()
{
b= "Initialization of Extendclass";
}
}
If we write code like this,
BaseClass a=new Extendclass ()
Procedure execution procedure execution steps
1. private string b= "Extendclass";
2. public string a= "BaseClass";
3. Public BaseClass ()
{
A= "Initialization of BaseClass";
}
4.public Extendclass (): Base ()
{
b= "Initialization of Extendclass";
}
This is the example I explained in C #, of course, other languages can be performed in different processes, as I know, the Java implementation process and C # is not only the same.
The process of his execution was
1. public string a= "BaseClass";
2. private string b= "Extendclass";
3. Public BaseClass ()
{
A= "Initialization of BaseClass";
}
4.public Extendclass (): Base ()
{
b= "Initialization of Extendclass";
}
VB.net is
1. public string a= "BaseClass";
2. Public BaseClass ()
{
A= "Initialization of BaseClass";
}
3. Private string b= "Extendclass";
4.public Extendclass (): Base ()
{
b= "Initialization of Extendclass";
}
All right, just write it here and do a good job.
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