java类变量的调用方式
从类的内部调用类变量,可以使用类名.变量,也可以直接使用变量进行调用:
public class Test {
static byte a = 1;
static short b = 2;
public static void main(String[] args) {
System.out.println("a="+a);
System.out.println("b="+Test.b);
}
}
输出结果:
a=1
b=2
而在类的外部调用类变量,只能使用类名.变量
public class Test {
static byte a = 1;
static short b = 2;
}
class Test2{
public static void main(String[] args) {
System.out.println("a="+Test.a);
System.out.println("b="+Test.b);
}
}
输出结果:
a=1
b=2
标签:调用,java,变量,System,println,static,Test,public
来源: https://www.cnblogs.com/ruoleecc/p/14290156.html