Tin Học >> Lập trình >> Java
|| C#
C++
Visual Basic
Visual Foxpro
C
Java
Pascal
Thiết Kế Web
ASP.NET
XML
CSS
PHP
Có 55 bài trong 6 trang (10 bài/trang) và bạn đang ở trang 3.
Which of the following will produce an answer that is closest in value to a double, d, while not being greater than d? A. (int)Math.min(d); B. (int)Math.max(d); C. (int)Math.abs(d); D. (int)Math.floor(d);..... What two statements are true about the result obtained from calling Math.random()? The result is less than 0.0. The result is greater than or equal to 0.0.. The result is less than 1.0. The result is greater than 1.0. The result is greater than or equal to 1.0. A. 1 and 2 B. 2 and 3........... What will be the output of the program? public class Test138 { public static void stringReplace (String text) { text = text.replace ('j' , 'c'); /* Line 5 */ } public static void bufferReplace (StringBuffer text) { text = text.append ("c"); /* Line 9 */ } public static void main (String args[]) { String textString = new String ("java"); StringBuffer textBuffer = new StringBuffer ("java"); /* Line 14 */ stringReplace(textString); bufferReplace(textBuffer); System.out.println (textString + textBuffer); } } A. java B. javac.......... What will be the output of the program? public class ExamQuestion7 { static int j; static void methodA(int i) { boolean b; do { b = i<10 | methodB(4); /* Line 9 */ b = i<10 || methodB(8); /* Line 10 */ }while (!b); } static boolean methodB(int i) { j += i; return true; } public static void main(String[] args) { methodA(0); System.out.println( "j = " + j ); } } A. j = 0 B. j = 4 C. j = 8 D. The code will run with no output.......... What will be the output of the program? public class BoolTest { public static void main(String [] args) { int result = 0; Boolean b1 = new Boolean("TRUE"); Boolean b2 = new Boolean("true"); Boolean b3 = new Boolean("tRuE"); Boolean b4 = new Boolean("false"); if (b1 == b2) /* Line 10 */ result = 1; if (b1.equals(b2) ) /* Line 12 */ result = result + 10; if (b2 == b4) /* Line 14 */ result = result + 100; if (b2.equals(b4) ) /* Line 16 */ result = result + 1000; if (b2.equals(b3) ) /* Line 18 */ result = result + 10000; System.out.println("result = " + result); } } ..... Which of the following statements is true? A. In an assert statement, the expression after the colon ( : ) can be any Java expression. B. If a switch block has no default, adding an assert default is considered appropriate. C. In an assert statement, if the expression after the colon ( : ) does not have a value, the assert's error message will be empty. D. It is appropriate to handle assertion failures using a catch clause........ Which statement is true? A. Calling Runtime.gc() will cause eligible objects to be garbage collected. B. The garbage collector uses a mark and sweep algorithm. C. If an object can be accessed from a live thread, it can't be garbage collected. D. If object 1 refers to object 2, then object 2 can't be garbage collected....... What will be the output of the program? public class Test { public static void main(String[] args) { int x = 0; assert (x > 0) ? "assertion failed" : "assertion passed" ; System.out.println("finished"); } } A. finished B. Compiliation fails. C. An AssertionError is thrown and finished is output........ class HappyGarbage01 { public static void main(String args[]) { HappyGarbage01 h = new HappyGarbage01(); h.methodA(); /* Line 6 */ } Object methodA() { Object obj1 = new Object(); Object [] obj2 = new Object[1]; obj2[0] = obj1; obj1 = null; return obj2[0]; } } Where will be the most chance of the garbage collector being invoked? A. After line 9 B. After line 10 C. After line 11 D. Garbage collector never invoked in methodA()....... What will be the output of the program? public class Test107 implements Runnable { private int x; private int y; public static void main(String args[]) { Test107 that = new Test107(); (new Thread(that)).start(); (new Thread(that)).start(); } public synchronized void run() { for(int i = 0; i < 10; i++) { x++; y++; System.out.println("x = " + x + ", y = " + y); /* Line 17 */ } } } A. Compilation error. B. Will print in this order: x = 1 y = 1 x = 2 y = 2 x = 3 y = 3 x = 4 y = 4 x = 5 y = 5... but the output will be produced by both threads running simultaneously.............. What will be the output of the program? class s1 extends Thread { public void run() { for(int i = 0; i < 3; i++) { System.out.println("A"); System.out.println("B"); } } } class Test120 extends Thread { public void run() { for(int i = 0; i < 3; i++) { System.out.println("C"); System.out.println("D"); } } public static void main(String args[]) { s1 t1 = new s1(); Test120 t2 = new Test120(); t1.start(); t2.start(); } } A. Compile time Error There is no start() method B. Will print in this order AB CD AB... C. Will print but not be able to predict the Order D. Will print in this order ABCD...ABCD............ Which method registers a thread in a thread scheduler? A. run(); B. construct(); C. start(); D. register();..... Assume the following method is properly synchronized and called from a thread A on an object B: wait(2000); After calling this method, when will the thread A become a candidate to get another turn at the CPU? A. After thread A is notified, or after two seconds. B. After the lock on B is released, or after two seconds. C. Two seconds after thread A is notified. D. Two seconds after lock B is released........ |