[Original] parent class (base class) and subclass BASICS (C #, java)

Source: Internet
Author: User

The idea of oo programming has become more and more common,

However, some basic things are still vague,

For example, the call sequence of the base class and subclass.

Here I use c # as an example to show you how:

(The capability is limited. If you have any flaws, please kindly advise ^_^)

For the following code
Public class baseClass
{
Public string a = "baseClass ";
Public baseClass ()
{
A = "initialize baseClass ";
}

}
Public class ExtendClass: baseClass
{
Private string B = "ExtendClass ";
Public ExtendClass (): base ()
{
B = "initialize ExtendClass ";

}

}
If we write code like this
BaseClass a = new ExtendClass ()
Procedure
1. Private string B = "ExtendClass ";
2. Public string a = "baseClass ";
3. public baseClass ()
{
A = "initialize baseClass ";
}
4. public ExtendClass (): base ()
{
B = "initialize ExtendClass ";

}
This is explained in the example of c #. Of course, the execution processes of other languages may be different. As far as I know, java's execution process is not only the same as c.

In Java, this declaration method is called object transformation object declaration. Its execution process is as follows:
1. Public string a = "baseClass ";
2. Private string B = "ExtendClass ";
3. public baseClass ()
{
A = "initialize baseClass ";
}
4. public ExtendClass (): base ()
{
B = "initialize ExtendClass ";

}

Vb.net is

1. Public string a = "baseClass ";
2. Public baseClass ()
{
A = "initialize baseClass ";
}

3. private string B = "ExtendClass ";

4. public ExtendClass (): base ()
{
B = "initialize ExtendClass ";

}
Now, let's write it here and enjoy your work.

Learn from each other ~ Common progress ~

O (partition _ partition) o...

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.