·您的位置: 首页 » 资源教程 » 编程开发 » JAVA、JSP » ????:java初始化?序

????:java初始化?序

类别: JAVA教程  评论数:0 总得分:0
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()就可以(需要了解重蒌)






-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1