The execution sequence after inheritance.

Source: Internet
Author: User

The execution sequence after inheritance.

Using System; namespace Test {// if the parent class is not constructed by default, The subclass must explicitly call the parameter-Containing Structure of the parent class in its constructor to ensure smooth instantiation of the subclass object! Public class MyClass {static MyClass () {Console. writeLine ("MyClass: Default static constructor");} public MyClass () {Console. writeLine ("MyClass: default constructor");} public MyClass (int a, int B) {Console. writeLine ("MyClass with parameter construction: a = {0}, B = {1 }. ", a, B) ;}} public class MyClass2: MyClass {static MyClass2 () {Console. writeLine ("MyClass2: Default static constructor");} public MyClass2 () {Console. writeLine ("MyClass2: default constructor");} public MyClass2 (int a, int B) {Console. writeLine ("MyClass2 with parameter construction: a = {0}, B = {1 }. ", a, B) ;}} public class MyClass3: MyClass2 {static MyClass3 () {Console. writeLine ("MyClass3: Default static constructor");} public MyClass3 () {Console. writeLine ("MyClass3: default constructor");} public MyClass3 (int a, int B) {Console. writeLine ("MyClass3 with parameter construction: a = {0}, B = {1 }. ", a, B) ;}} public class runMyApp {static void Main () {MyClass3 my = new MyClass3 (3, 4 );}}}

 

Related Article

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.