using System;
public class test
{
static public int sctr;
public int ctr; public void routine()
{
Console.WriteLine("In the routine - ctr = {0} / sctr = {1}\n", ctr, sctr);
}
static test()
{
sctr = 100;
Console.WriteLine("In Static Constructor - sctr = {0}\n", sctr);
} public test()
{
ctr++;
sctr++;
Console.WriteLine("In Constructor - ctr = {0} / sctr={1}\n", ctr, sctr);
}
}class TestApp
{
public static void Main()
{
Console.WriteLine("Start of Main method..."); Console.WriteLine("Creating first object....");
test first = new test();
Console.WriteLine("Creating second object...");
test second = new test(); Console.WriteLine("Calling first routine...");
first.routine(); Console.WriteLine("Creating third object...");
test third = new test();
Console.WriteLine("Calling third routine...");
third.routine();
Console.WriteLine("Calling second routine....");
second.routine(); Console.WriteLine("End of Main method");
}
}//输出结果
//Start of Main method...
//Creating first object....
//In Static Constructor - sctr = 100//In Constructor - ctr = 1 / sctr=101//Creating second object...
//In Constructor - ctr = 1 / sctr=102 //sctr不是静态变量吗?为什么它的值在增加?
//Calling first routine...
//In the routine - ctr = 1 / sctr = 102//Creating third object...
//In Constructor - ctr = 1 / sctr=103//Calling third routine...
//In the routine - ctr = 1 / sctr = 103//Calling second routine....
//In the routine - ctr = 1 / sctr = 103//End of Main method
public class test
{
static public int sctr;
public int ctr; public void routine()
{
Console.WriteLine("In the routine - ctr = {0} / sctr = {1}\n", ctr, sctr);
}
static test()
{
sctr = 100;
Console.WriteLine("In Static Constructor - sctr = {0}\n", sctr);
} public test()
{
ctr++;
sctr++;
Console.WriteLine("In Constructor - ctr = {0} / sctr={1}\n", ctr, sctr);
}
}class TestApp
{
public static void Main()
{
Console.WriteLine("Start of Main method..."); Console.WriteLine("Creating first object....");
test first = new test();
Console.WriteLine("Creating second object...");
test second = new test(); Console.WriteLine("Calling first routine...");
first.routine(); Console.WriteLine("Creating third object...");
test third = new test();
Console.WriteLine("Calling third routine...");
third.routine();
Console.WriteLine("Calling second routine....");
second.routine(); Console.WriteLine("End of Main method");
}
}//输出结果
//Start of Main method...
//Creating first object....
//In Static Constructor - sctr = 100//In Constructor - ctr = 1 / sctr=101//Creating second object...
//In Constructor - ctr = 1 / sctr=102 //sctr不是静态变量吗?为什么它的值在增加?
//Calling first routine...
//In the routine - ctr = 1 / sctr = 102//Creating third object...
//In Constructor - ctr = 1 / sctr=103//Calling third routine...
//In the routine - ctr = 1 / sctr = 103//Calling second routine....
//In the routine - ctr = 1 / sctr = 103//End of Main method
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货