A practice made by the C # middle school constructor and the destructor

xiaoxiao2021-03-06  45

Using system;

Class a {public a () // Because this method is called because of an inherited class, this function cannot be saved, unless in the inherited structure, the {Console.Writeline ("a constructed") ("a constructed") ("a constructed") ("a constructed") ("a constructed") ("a constructed");

Public a (int a) {console.writeline ("a constructed has parameter";}

Public void methoda () {console.writeline ("call methoda");}

~ A () {console.writeline ("a destructed");}}

Class B: a {public b () {console.writeline ("b constructed");}

Public void methodb () {console.writeline ("call methodb");}

~ B () {Console.writeline ("b destructed");}};

Class c {public static void main () {a d; d = new a (7); d.Methoda ();

Console.writeLine ("**************");

B E = new b (); e.Methodb ();}}; running result: a Constructed Have ParameterCall Methoda ************* A Constructedb Constructeda Destructeda Destructed Destructed Decoction Call is when the GC is performed, so you cannot predict the destructor, where to run.

转载请注明原文地址:https://www.9cbs.com/read-54818.html

New Post(0)