import java.io.*; class Base{ public static void amethod() throws FileNotFoundException{ //这里面居然也可以是空的 } } public class ExcepDemo extends Base{ public static void main(String argv[]){ ExcepDemo e = new ExcepDemo(); } public static void amethod(){ } //我以为这里一定要抛出异常呢 protected ExcepDemo(){ try{ DataInputStream din = new DataInputStream(System.in); System.out.println("Pausing"); din.readChar(); System.out.println("Continuing"); this.amethod(); }catch(IOException ioe) {} } } Mutiple: 1) Compile time error caused by protected constructor 2) Compile time error caused by amethod not declaring Exception 3) Runtime error caused by amethod not declaring Exception 4) Compile and run with output of "Pausing" and "Continuing" after a key is hit the answer is 4. who can give me an explanation? thank you !
public class Inc{ public static void main(String argv[]){ Inc inc = new Inc(); int i =0; inc.fermin(i); i = i++; System.out.println(i); } void fermin(int i){ i++; } } who can explain why the assignment to var i has no effect? thank you
i got it thank you ! i just want to know the reason,but i can not find someone to explain the answer.so i post it . now i know how to get the information about my problem
public class SyncTest { 2 private int x; 3 private int y; 4 private d void setX( int i ) { x = i; } 5 private synchronized void setY( int i ) { y = i; } 6 public void setXY( int i ) { setX(i); setY(i); } 7 public synchronized boolean check() { return x != y; } 8 } Under which condition will check return true when called from a different class?
A. check can never return true. B. check can return true when setXY is called by multiple threads. C. check can return true when multiple threads call setX and setY separately. D. check can return true only if SyncTest is changed to allow x and y to be set separately.