日期:2014-05-20  浏览次数:20581 次

java方法调用问题
class   test{
  private   static   int   j   =   0;
  private   static   boolean   methodB(int   k)   {
            j   +=   k;
              return   true;
  }
  public   static   void   methodA(int   i)   {
  boolean   b;
b   =   i   <   10   |methodB   (4);
  b   =   i   <   10   ||   methodB   (8);
}
  public   static   void   main   (String   args[]   )   {
  methodA   (1);
System.out.println(j);
  }
}

    为何j=4?
      请教!

------解决方案--------------------
b = i < 10 || methodB (8);这句执行到i <10发现为true就没有执行methodB
------解决方案--------------------
楼上正解~~~~~~~
------解决方案--------------------
LZ对一些细节还是要仔细了解啊

syhan(藏书人)

正解
------解决方案--------------------
短路问题