public class Test { //1.第一步,准备加载类 public static void main(String[] args) { new Test(); //4.第四步,new一个类,但在new之前要处理匿名代码块 } static int num = 4; //2.第二步,静态变量和静态代码块的加载顺序由编写先后决定 { num += 3; System.out.println("b"); //5.第五步,按照顺序加载匿名代码块,代码块中有打印 } int a =
static 修饰符能够与变量.方法一起使用,表示是“静态”的. 静态变量和静态方法能够通过类名来访问,不需要创建一个类的对象来访问该类的静态成员,所以static修饰的成员又称作类变量和类方法.静态变量与实例变量不同,实例变量总是通过对象来访问,因为它们的值在对象和对象之间有所不同. 请看下面的例子: public class Demo { static int i = 10; int j; Demo() { this.j = 20; } public static void main(Str
static 修饰符能够与变量.方法一起使用,表示是“静态”的. 静态变量和静态方法能够通过类名来访问,不需要创建一个类的对象来访问该类的静态成员,所以static修饰的成员又称作类变量和类方法.静态变量与实例变量不同,实例变量总是通过对象来访问,因为它们的值在对象和对象之间有所不同. 请看下面的例子: public final class Demo { static int i = 10; int j; Demo() { this.j = 20; } public static void ma
最近考试出了一个很简单的题,看看他们对java常量,变量,静态变量的理解,代码如下: public class TestVar { /** * JAVA基础,常量,变量,静态变量 */ public static void main(String[] args) { // TODO Auto-generated method stub A a = new A(); A b = new A(); System.out.println("a.aa.value =" + a.aa); Sys
//据说这是一道阿里巴巴面试题,先以这道题为例分析下 public class Text { public static int k = 0; public static Text t1 = new Text("t1"); public static Text t2 = new Text("t2"); public static int i = print("i"); public static int n = 99; public int j
测试代码 public class SingleTest { public static String v = "StaticValue"; static { System.out.println("static静态变量:" + v); System.out.println("static静态块"); } { System.out.println("构造块"); } public SingleTest() { System.o