java static 代码_java中一段关于static代码

classValue{staticintc=0;Value(){c=15;}Value(inti){c=i;}staticvoidinc(){c;}}classCount{publicstaticvoidprt(Strings){System.out.println(s);}Valuev=newValue(10);staticValuev...

class Value{

static int c=0;

Value(){

c=15;

}

Value(int i){

c=i;

}

static void inc(){

c ;

}

}

class Count{

public static void prt(String s){

System.out.println(s);

}

Value v=new Value(10);

static Value v1,v2;

static{

prt("v1.c=" v1.c " v2.c=" v2.c);

v1=new Value(27);

prt("v1.c=" v1.c " v2.c=" v2.c);

v2=new Value(15);

prt("v1.c=" v1.c " v2.c=" v2.c);

}

public static void main(String[] args){

Count ct=new Count();

prt("ct.c=" ct.v.c);

prt("v1.c=" v1.c " v2.c=" v2.c);

v1.inc();

prt("v1.c=" v1.c " v2.c=" v2.c);

prt("ct.c=" ct.v.c);

}

}

运行结果如下:

v1.c=0 v2.c=0

v1.c=27 v2.c=27

v1.c=15 v2.c=15

ct.c=10

v1.c=10 v2.c=10

v1.c=11 v2.c=11

ct.c=11

这段代码一点都看不懂啊 我是java菜鸟 请高人详解

这段程序是怎么运行的

程序中的static{大括号内容}具体是什么意思 这里的static是一个方法吗?

还有

ct.v.c 具体是什么意思啊?对象.对象.对象?

很是迷茫····

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值