class Program { static int i = getNum(); int j = getNum(); ; static int getNum() { return num; } static void Main(string[] args) { Console.WriteLine("i={0}", i); Console.WriteLine("j={0}", new Program().j); Console.Read(); } }//输出值为i=0…
先看下JDK中的说明: java.lang.Object java.lang.Class<T> Instances of the class Class represent classes and interfaces in a running Java application. An enum is a kind of class and an annotation is a kind of interface. Every array also belongs to a class…
直接上代码: 代码1: public class ConstroctTest { private static ConstroctTest test = new ConstroctTest(); //静态变量sta1 未赋予初始值 public static int sta1; //静态变量sta1 赋予初始值20 public static int sta2 = 20; //构造方法中对于静态变量赋值 private ConstroctTest() { sta1 ++ ; sta2 ++ ;…
由static修饰,属于整个类,被类对象共享, 可以由类名,对象名访问 static可以修饰变量,方法,代码块 public class HelloWorld { static String className = "Java"; public static void main (String[] args){ System.out.println(HelloWorld.className); } } 静态方法:? public class HelloWorld{ static int…
在Java语言中,所有的变量在使用前必须声明.声明变量的基本格式如下: type identifier [ = value][, identifier [= value] ...] ; 格式说明:type为Java数据类型.identifier是变量名.可以使用逗号隔开来声明多个同类型变量.以下列出了一些变量的声明实例.注意有些包含了初始化过程: int a, b, c; // 声明三个int型整数:a. b.cint d = 3, e = 4, f =…