Java引用变量的两个类型,一个是编译的类型,一个是运行类型,编译时类型由声明该变量时变量的类型决定,运行时类型由实际赋给该变量的对象决定,出现了多态,也就是动态绑定。
package day1108;
public class Person {
{
int a=6;
if(a>4)
{
System.out.println("frist1");
}
}
{
System.out.println("Secon");
}
public Person()
{
System.out.println("constructor");
}
public static void main(String[] args){
new Person();
}
}
运行结果
frist1
Secon
constructor
创建Person对象调用Person的两个初始代码块和构造方法,顺序如结果。