1.构造器:与类同名且没有返回值,用来初始化类属性: 构造器又分为无参构造器和有参构造器 1.1:无参构造器 public class Contruction{ ...属性... public Contruction(){}//无参构造器,不写,系统会自动添加 } 1.2:有参构造器 public class Contruction { private int i; public Contruction( int i){/*有参构造器,如果你定义了一个有参数的构造器,那么你在实例化对象的时候必须…
本文讨论Java中(静态)变量.(静态)代码块的执行顺序 首先创建3个类: 1.Foo类,用于打印变量 public class Foo { public Foo(String word) { System.out.println(word); } } 2.Parent类 public class Parent { static Foo FOO = new Foo("Parent's static parameter"); Foo foo = new Foo("Parent'…
http://www.cnblogs.com/naruto469/p/3608459.html public class Print { 2 3 public Print(String s){ 4 System.out.print(s + " "); 5 } 6 } 1 public class Test1 { 2 3 public static Print obj1 = new Print("1"); 4 5 public Print obj2 = new Pri…
验证证的方法是写code,如下: public class test { static class A { public static String name = "hello"; static { System.out.println("A static block1"); //1 } { System.out.println("A block3"); //3 } public A() { System.out.println("A…