VC和GCC静态变量析构顺序不同(金庆的专栏)静态变量析构顺序正常情况下是构造的反序.但是VC对DLL中的静态变量好像是需等待DLL卸载时再析构,表现为主程序中的静态变量先析构,DLL中的静态变量后析构.VC测试版本为VC2010Express.例如:class A {};static A s_a;int main(){ extern B & getB(); // defined in b.dll B & rb = getB(); return 0;}b.dll中有个静…
直接上代码: 代码1: public class ConstroctTest { private static ConstroctTest test = new ConstroctTest(); //静态变量sta1 未赋予初始值 public static int sta1; //静态变量sta1 赋予初始值20 public static int sta2 = 20; //构造方法中对于静态变量赋值 private ConstroctTest() { sta1 ++ ; sta2 ++ ;…
class Program { static int i = getNum(); int j = getNum(); ; static int getNum() { return num; } static void Main(string[] args) { Console.WriteLine("i={0}", i); Console.WriteLine("j={0}", new Program().j); Console.Read(); } }//输出值为i=0…
//据说这是一道阿里巴巴面试题,先以这道题为例分析下 public class Text { public static int k = 0; public static Text t1 = new Text("t1"); public static Text t2 = new Text("t2"); public static int i = print("i"); public static int n = 99; public int j…
public class Test { //1.第一步,准备加载类 public static void main(String[] args) { new Test(); //4.第四步,new一个类,但在new之前要处理匿名代码块 } static int num = 4; //2.第二步,静态变量和静态代码块的加载顺序由编写先后决定 { num += 3; System.out.println("b"); //5.第五步,按照顺序加载匿名代码块,代码块中有打印 } int a =…
为了弄清这个代码,写了个测试,但是测试的结果和往上的代码有所差别,仁者见仁,智者见智了.如果我的测试用例用问题,欢迎指出. 首先,方法的是在被调用时执行,但是静态方法在所有地方都可以调用,应该在很早的时候就被编译了.这个测试依赖静态方法来输出顺序. public class WhenCodeThread : ITestSample { public class Test : TestBase { int instanceParam2 = staticFunction("子类实体变量")…
测试代码 public class SingleTest { public static String v = "StaticValue"; static { System.out.println("static静态变量:" + v); System.out.println("static静态块"); } { System.out.println("构造块"); } public SingleTest() { System.o…