static成員與non static成員的差異-
class Test
{
static void showA()
{
........
........
}
void showB()
{
.......
.......
}
}
//Test.class
Step1.載入
[ ]
stack
[ ]
Heap
[ [showA] [showA] ]
static
叫用showA:Test.showA()
註:static方法又稱為類別方法
Step2.建立物件
Test oo1=new Test();
Test oo2=new Test();
[ [oo1][oo2] ]
stack
[ [showB][showB] ]
Heap
[ [showA] ]
static
叫用 showB:oo1.showB()
oo2.showB()
註:oo1.showB() != oo2.showB()
叫用showA:Test.showA()
oo1.showA()
oo2.showA()
註:Test.showA() == oo1.showA() == oo2.showA()
沒有留言:
張貼留言