class Bowl {
Bowl(int er)
{
System.out.println("Bowl(" + er + ")");
}
void f(int er)
{
System.out.println("f(" + er + ")");
}
}class Table
{
static Bowl b1 = new Bowl(1);
Table()
{
System.out.println("Table()");
b2.f(1);
}
void f2(int er)
{
System.out.println("f2(" + er + ")");
}
static Bowl b2 = new Bowl(2);
}class Cupboard
{
Bowl b3 = new Bowl(3);
static Bowl b4 = new Bowl(4);
Cupboard()
{
System.out.println("Cupboard()");
b4.f(2);
}
void f3(int er)
{
System.out.println("f3(" + er + ")");
}
static Bowl b5 = new Bowl(5);
}public class StaticInitialization
{
public static void main(String[] args)
{
System.out.println("Creating new Cupboard() in main");
new Cupboard();
System.out.println("Creating new Cupboard() in main");
new Cupboard();
t2.f2(1);
t3.f3(1);
}
static Table t2 = new Table();
static Cupboard t3 = new Cupboard();
}
输出结果:
Bowl(1)
Bowl(2)
Table()
f(1)
Bowl(4)
Bowl(5)
Bowl(3)
Cupboard()
f(2)
Creating new Cupboard() in main
Bowl(3)
Cupboard()
f(2)
Creating new Cupboard() in main
Bowl(3)
Cupboard()
f(2)
f2(1)
f3(1)
本人自学JAVA,现在是菜鸟级别,希望高人解释一下这个程序
Bowl(int er)
{
System.out.println("Bowl(" + er + ")");
}
void f(int er)
{
System.out.println("f(" + er + ")");
}
}class Table
{
static Bowl b1 = new Bowl(1);
Table()
{
System.out.println("Table()");
b2.f(1);
}
void f2(int er)
{
System.out.println("f2(" + er + ")");
}
static Bowl b2 = new Bowl(2);
}class Cupboard
{
Bowl b3 = new Bowl(3);
static Bowl b4 = new Bowl(4);
Cupboard()
{
System.out.println("Cupboard()");
b4.f(2);
}
void f3(int er)
{
System.out.println("f3(" + er + ")");
}
static Bowl b5 = new Bowl(5);
}public class StaticInitialization
{
public static void main(String[] args)
{
System.out.println("Creating new Cupboard() in main");
new Cupboard();
System.out.println("Creating new Cupboard() in main");
new Cupboard();
t2.f2(1);
t3.f3(1);
}
static Table t2 = new Table();
static Cupboard t3 = new Cupboard();
}
输出结果:
Bowl(1)
Bowl(2)
Table()
f(1)
Bowl(4)
Bowl(5)
Bowl(3)
Cupboard()
f(2)
Creating new Cupboard() in main
Bowl(3)
Cupboard()
f(2)
Creating new Cupboard() in main
Bowl(3)
Cupboard()
f(2)
f2(1)
f3(1)
本人自学JAVA,现在是菜鸟级别,希望高人解释一下这个程序
楼主【Chaneo6】截止到2008-07-18 23:22:12的历史汇总数据(不包括此帖):
发帖的总数量:1 发帖的总分数:0 每贴平均分数:0
回帖的总数量:18 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:1 结贴的总分数:0
无满意结贴数:1 无满意结贴分:20
未结的帖子数:0 未结的总分数:0
结贴的百分比:100.00% 结分的百分比:---------------------
无满意结贴率:100.00% 无满意结分率:---------------------
敬礼!