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 具体是什么意思啊?对象.对象.对象?
很是迷茫····
展开