public class HelloWorld {
String name;
String sex;
static int age;
public HelloWorld(){
System.out.println("非静态修饰,构造方法初始化块");
name="Michil";//初始化name值
{
System.out.println("非静态修饰");
sex="man";//初始化sex值
}
static{
System.out.println("静态修饰static");
age=24;//静态初始化age值
}
}
public void show(){
System.out.println("姓名:"+name+"性别:"+sex+"年龄:"+age);
}
public static void main(String[] args) {
HelloWorld hello=new HelloWorld();
hello.show();
HelloWorld hello2=new HelloWorld();
}
相关分类