类创建
Class ATypeName{.........}ATypeName a = new ATypename
若字段位于类中且为基本类型,则会被赋予初值。但在函数中,需要进行初始化,否则出错。
static关键字
- 放在filed前,共享存储空间。
例:
class StaticTest{static int i = 100;}StaticTest s1 = new StaticTest;StaticTest s2 = new StaticTest;Static.i++;
在上述代码中,s1.i与s2.i实际共用同一块内存空间,即s1与s2均可对其进行操作。
2.放在function前,可以直接调用静态方法
class Test{static void func(){StaticTest.i++;}}//直接调用Test.func();
```
