为了账号安全,请及时绑定邮箱和手机立即绑定

为什么在eclipse写上static修饰年龄初始化块会报错

为什么在eclipse写上static修饰年龄初始化块会报错

qq_裸奔的蜗牛_1 2016-03-06 11:11:29
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();            }
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 2228 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信