首页 > 代码库 > java class 初始化
java class 初始化
the order of execution is: static initializer, instance initializer, constructor
1.Initializing Fields
public class BedAndBreakfast { // initialize to 10 public static int capacity = 10; // initialize to false private boolean full = false;}
2.Static Initialization Blocks
static { // whatever code is needed for initialization goes here}
3.Initializing Instance Members
{ // whatever code is needed for initialization goes here}
4. constructor
5. example
public class t1 { { System.out.println("Empty block"); } static { System.out.println("Static block"); } public t1() { System.out.println("constructor block"); } public static void main(String[] args) { t1 t = new t1(); }}
http://docs.oracle.com/javase/tutorial/java/javaOO/initial.html Initializing Fields
http://www.javatpoint.com/instance-initializer-block Instance initializer block:
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。