写出下面代码的输出结果,为什么?
public class Test2{
static int i=5;
public static void main(String[] args){
Father father = new Child();
father = new Child();
System.out.println( (change()==3)?i+15:i+10.0 );
}
public static int change(){
if(i==5){
i = i+10;
}
return i = i/5;
}
}
class Father{
public Father(){
System.out.println("father...");
}
static{
System.out.println("father2");
}
}
class Child extends Father{
public Child(){
System.out.println("child...");
}
static{
System.out.println("child2");
}
}
/*输出结果:
father2
child2
father...
child...
father...
child...
18.0
*/
/*
?号表达式中,冒号两边的表达式的数据类型必须一致 (若不同则自动向高精度靠齐)
int x=3,y=1;
System.out.println( (x==3)?y+1:y+10 ); //结果:2
System.out.println( (x==3)?y+1:y+10.0 ); //结果:2.0
*/