????:java初始化?序
类别: JAVA教程
class Bowl {
Bowl(int marker) {
System.out.println("Bowl(" + marker + ")");
}
void f1() {
System.out.println("Ok");
}
}
class Cupboard {
Bowl b1 = new Bowl(1);
static Bowl b2 = new Bowl(2);
Cupboard() {
System.out.println("Cupboard()");
}
static Bowl b3 = new Bowl(3);
}
class Table {
Table() {
System.out.println("Table()");
}
Table(String a,int i){
this();
System.out.println("Ok");
}
}
public class Order {
static Cupboard t1 = new Cupboard();
static Table t2;
Bowl t3 = new Bowl(10);
void print() {
t3.f1();
}
public static void main(String[] args) {
System.out.println("Creating new Cupboard() in main");
new Cupboard();
System.out.println("Creating new Cupboard() in main");
Order od = new Order();
od.t3.f1();
Table t4 = new Table("aa",1);
}
}
程序忒行?r:砚蒌Order.class,忒行Order??中的static?K
static Cupboard t1 = new Cupboard();
呃??造了一??Cupboard?ο蟋??造?ο??r,??砚蒌Cupboard??,
也是先?绦畜tatic?K
static Bowl b2 = new Bowl(2);//??建一??Bowl?ο蟋咿程和Cupboard一?蝇??整用??造函?导br>static Bowl b3 = new Bowl(3);//同上
然後?绦屑br> Bowl b1 = new Bowl(1);//??建一??Bowl?ο蠹br>然後?绦???造函?德owl()
接下?砗
static Table t2;//呃只是??明,?K?]有??建?ο蟋不用理??
然後:
?绦许ain函?抵械恼Z句
System.out.println("Creating new Cupboard() in main");
new Cupboard(); //注意的是,static只??初始化一次
System.out.println("Creating new Cupboard() in main");
Order od = new Order();//??建Order?ο蟋同上
od.t3.f1();
Table t4 = new Table("aa",1);//??建了Table,注意呃彦??造函?档恼{用this()就可以(需要了解重蒌)
Bowl(int marker) {
System.out.println("Bowl(" + marker + ")");
}
void f1() {
System.out.println("Ok");
}
}
class Cupboard {
Bowl b1 = new Bowl(1);
static Bowl b2 = new Bowl(2);
Cupboard() {
System.out.println("Cupboard()");
}
static Bowl b3 = new Bowl(3);
}
class Table {
Table() {
System.out.println("Table()");
}
Table(String a,int i){
this();
System.out.println("Ok");
}
}
public class Order {
static Cupboard t1 = new Cupboard();
static Table t2;
Bowl t3 = new Bowl(10);
void print() {
t3.f1();
}
public static void main(String[] args) {
System.out.println("Creating new Cupboard() in main");
new Cupboard();
System.out.println("Creating new Cupboard() in main");
Order od = new Order();
od.t3.f1();
Table t4 = new Table("aa",1);
}
}
程序忒行?r:砚蒌Order.class,忒行Order??中的static?K
static Cupboard t1 = new Cupboard();
呃??造了一??Cupboard?ο蟋??造?ο??r,??砚蒌Cupboard??,
也是先?绦畜tatic?K
static Bowl b2 = new Bowl(2);//??建一??Bowl?ο蟋咿程和Cupboard一?蝇??整用??造函?导br>static Bowl b3 = new Bowl(3);//同上
然後?绦屑br> Bowl b1 = new Bowl(1);//??建一??Bowl?ο蠹br>然後?绦???造函?德owl()
接下?砗
static Table t2;//呃只是??明,?K?]有??建?ο蟋不用理??
然後:
?绦许ain函?抵械恼Z句
System.out.println("Creating new Cupboard() in main");
new Cupboard(); //注意的是,static只??初始化一次
System.out.println("Creating new Cupboard() in main");
Order od = new Order();//??建Order?ο蟋同上
od.t3.f1();
Table t4 = new Table("aa",1);//??建了Table,注意呃彦??造函?档恼{用this()就可以(需要了解重蒌)
- 上一篇: 如何在 vim 中更好的编辑 java 文件
- 下一篇: java报表EXCEL解决方案
-= 资 源 教 程 =-
文 章 搜 索