首页 > 试题广场 >

请写出以下java代码的输出内容[$##$] publi

[填空题]
请写出以下java代码的输出内容1
public class TestCount {
   
public static void main(String args[]) {
       
Count count = new Count( );
       
count.count(count.getCount( )).getCount( );
       
new Count( ).count(count.getCount( ));
    }
   
public static class Count {
        volatile Integer count = 2018;
       
public Count count(Integer count) {
           
System.out.println(++count);
           
return this;
       
}
       
public Integer getCount( ) {
           
System.out.println(++count);
           
return count;
       
}
    }
}

代码的执行过程
count.(2)count((1)count.getCount( )).(3)getCount( );
 
newCount( ).(5)count((4)count.getCount( ));
(1)输出2019,然后返回值是2019,传给count(int count)函数,此时,count对象内的变量值为2019
(2)count函数使用的是getCount()返回的一个临时变量,值为2019,所以打印2020,此时count对象内的count值为2019
(3)getCount() 使用的是count对象里面的count变量,输出2020,此时count对象内的count值为2020
(4)getCount() 使用的是count对象里面的count变量,输出2021,并且返回一个临时的变量2021,此时count对象内的count值为2021
(5)count()使用的是(4)中函数返回的临时变量2021,所以打印2022,此时count对象内的count值为2021
发表于 2020-01-15 20:37:59 回复(2)
哪位牛油来解释一下,不太懂
发表于 2020-01-04 14:01:32 回复(0)
就(1).看不到题目!
发表于 2019-08-13 17:28:12 回复(0)