分类: Java
2008-08-03 23:51:13
Data Type |
Size(bit) |
Default Value (for fields) |
byte |
8 |
0 |
short |
16 |
0 |
int |
32 |
0 |
long |
64 |
|
float |
32 |
|
double |
64 |
0.0d |
char |
16 |
'\u0000' |
boolean |
1 |
false |
package javatutorials;
/**
*
* @author wanpor
*/
public class Variable {
//定义一些静态变量
static byte a ;
static short b;
static int c;
static long d;
static float e;
static double f;
static char g;
static boolean h;
public static void main(String[] args){
Variable var = new Variable();
var.printDefault();
var.printValue();
}
//打印各个静态变量的值
void printDefault(){
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
System.out.println(e);
System.out.println(f);
System.out.println(g);
System.out.println(h);
}
//改变静态变量的值,并打印出来
void printValue(){
a = 123;
b = 12345;
c = 12345678;
d = 1234567890;
e =
f = 123456.123456;
g = 'C';
h = true;
this.printDefault();
}
void PrintByte(){
byte age = 26;
System.out.println(age);
}
}
1. 文件名称:Variable.java
2. 静态变量的定义:static type varibaleName;使用静态变量只属于class,由编译器对其进行分配默认值;
3. printDefault成员函数打印各个变量的值;
printValue成员函数对各个静态变量进行赋值,并打印各个值;
|