Test Corejava

Chia sẻ: Nguyen Hong Thuy | Ngày: | Loại File: DOC | Số trang:7

0
76
lượt xem
17
download

Test Corejava

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Test Corejava 1) Which of the following is a correct signature for the main method? a) static void main(String[] args[]) c) public void main(String[] args) *b) public static void main(String[] args) d) public static void main(Strings[] args) 2) What

Chủ đề:
Lưu

Nội dung Text: Test Corejava

  1. Test Corejava 1) Which of the following is a correct signature for the main method? [0.5] a) static void main(String[] args[]) c) public void main(String[] args) *b) public static void main(String[] args) d) public static void main(Strings[] args) 2) What value does readLine() return when it has reached the end of the file? [0.5] a) 1 c) 0 b) -1 *d) null 3) Which of the Boolean expressions below is incorrect? (choose 2) [0.5] *a) (true) && (3 => 4) c) (x > 0) || (x < 0) b) !(x > 0) && (x > 0) *d) (x != 0) || (x = 0) 4) To declare an int variable number with initial value 2, you write [0.5] a) int number = 2L; *c) int number = 2; b) int number = 2l; d) Int number = 2.0; 5) What value does read () return when it has reached the end of the file? [0.5] a) 1 c) 0 *b) -1 d) Null 6) Which of these data type requires the largest amount of memory? [0.5] a) Float c) short *b) Double d) byte 7) Suppose x=0 and y=0 what is x after evaluating the expression (y >=0) || (x++ > 0)? [1] a) 1 *c) 0 b) -1 d) null 8) Suppose x = 1, y = -1, and z = 1. What is the printout of the following statement? [0.5] if (x > 0) if (y > 0) System.out.println(“x > 0 and y > 0”); else if (z > 0) System.out.println(“x < 0 and z > 0”); a) x > 0 and y > 0; c) x 0; d) None of the above. 9) What is y after the following switch statement is executed? [0.5] 2002 / Sem 1 – ACCP 2003 Q.P. Page 1 of 7
  2. x = 3; switch (x+3) { case 6: y = 0; case 7: y = 1; default: y += 2; } a) 1 c) 0 b) 2 *d) 3 10) What is sum after the following loop terminates? [1] int sum = 0; int item = 0; do { item++; sum += item; if (sum > 7) break; } while (item < 6); *a) 10 c) 6 b) 5 d) 8 11) Analyze the following code: [0.5] public class Test { public static void main (String args[]) { int i = 0; for (i=0; i
  3. ++z; } a) The if condition should use a prefix *c) There is a missing } before the else. operator instead of a postfix operator. *b) The if condition must be a boolean d) There is no break statement to allow control expression, not a numeric expression. to transfer out of the if statement. 13) Which of the following modifiers must be present for a method inside the main class [1] to be called inside the main method? a) public *c) static b) private d) None of the above is necessary. 14) Which of the following are illegal identifiers? (choose 2) [1] *a) 2variable c) _whatavariable b) variable2 d) _3_ e) $anothervar *f) #myvar 15) What are the three ways in which a thread can enter the waiting state?(choose 3) [0.5] *a) Sleep() *c) Suspend() *b) Wait() d) Start() e) Stop() 16) Which of the following are true about the finally clause of a try-catch-finally [0.5] statement? a) It is only executed after a catch clause has executed b) It is only executed after a catch clause has not executed *c) It is always executed unless its thread terminates d) It is only executed if an exception is thrown 17) Which layout manager can divide the container into a grid ? [0.5] a) CardLayout c) BorderLayout b) FlowLayout *d) GridLayout 18) Which of the following will output -4.0 [1] a) System.out.println(Math.floor(-4.7)); *c) System.out.println(Math.ceil(-4.7)); b) System.out.println(Math.round(-4.7)); d) System.out.println(Math.min(-4.7)); 19) Which of the following is the super class of these classes - ContainterEvent, [1] FocusEvent, InputEvent, PaintEvent, WindowEvent. Select the one correct answer. a) ActionEvent b) AdjustmentEvent *c) ComponentEvent d) ItemEvent
  4. e) TextEvent f) Event 20) _________ and ________ are required attributes that give the size ( in pixels) of the [0.5] applet display area. *a) width, height b) vspace, hspace c) param name, param value 21) Which methods will cause a Frame to be displayed? [0.5] *a) show() c) Display() b) SetVisible() d) DisplayFrame() 22) Which of these is a legal definition of a method named m assuming it throws [0.5] IOException, and returns void. Also assume that the method does not take any arguments. Select all correct answers. *a) void m() throws IOException{} c) void m(void) throws IOException{} b) void m() throw IOException{} d) m() throws IOException{} 23) The ___________ class is the superclass of the Exception class [0.5] a) Exception c) Error *b) Throwable d) Runtime Exception 24) static void nPrint(String message, int n) [0.5] { while (n > 0) { System.out.print(message); n--; } } What is k after invoking nPrint()? int k = 2; nPrint(“A message”, k); a) 0 b) 1 *c) 2 d) None of the above. 25) What will be printed out if this code is run with the following command line? [0.5] Java myprog good morning sir public class myprog{ Public static void main(String argv[]) { System.out.println(argv[0]) } } a) myprog
  5. *b) good c) morning d) Exception raised: “java.lang.ArrayIndexOutOfBoundsException: 2” 26) What most closely matches the appearance when this code runs? [1] Import java.awt.*; Public class CompLay extends Frame{ Public static void main(String argv[]){ CompLay cl = new CompLay(); } CompLay(){ Panel p = new Panel(); p.setBackground(Color.pink); p.add(new Button(“One”)); p.add(new Button(“Two”)); p.add(new Button(“Three”)); add(“South”,p); setLayout(new FlowLayout()); setSize(300,300); setVisible(true); } } a) The buttons will run from left to right along the bottom of the Frame *b) The buttons will run from left to right along the top of the frame c) The buttons will not be displayed d) Only button three will show occupying all of the frame 27) Which is the correct syntax for to draw a line using the drawLine() method? [0.5] *a. void drawLine(int startX, int startY, int endX, int endY) c) void drawLine(int startX, int endX) b void drawLine(int startX, int startY, int startZ) 28) Suppose that f is an instance of Foo [1] class Foo { int i; static int s; void imethod() {} static void smethod() {} } Which of the following statements is incorrect? A. System.out.println(Foo.s); *B.System.out.println(Foo.i); C. f.imethod(); D. Foo.smethod(); 29) Given a component, comp, and a container, cont, that is organized according to a [1]
  6. FlowLayout, which of the following should be used to add comp to the container. *a) cont.add(comp); b) comp.add(cont); c) cont.addComponent(comp); d) cont.addAllComponents(); 30) What is the output of the following code? [0.5] public class Test { public static void main(String[] args) { String s1 = new String("Welcome to Java!"); String s2 = new String("Welcome to Java!"); if (s1 == s2) System.out.println("s1 is equal to s2"); else System.out.println("s1 is not equal to s2"); } } a. s1 is equal to s2 *b. s1 is not equal to s2 31) When you implement a method that is defined in a superclass, you ___ the original method. [0.5] A. overload C. copy *B. override D. call 32) Which of the following statements registers a panel object p as a listener for a button variable jbt? [0.5] *A. jbt.addActionListener(p); C.jbt.addActionEventListener(p); B. addActionListener(p); D. jbt.addEventListener(p); 33) Which of the following statements will not convert a string s into an integer? [0.5] A. i = Integer.parseInt(s); C. i = Integer.valueOf(s).intValue(); B. i = (new Integer(s)).intValue(); *D. i = Integer.valueOf(s); 34) The interface __________ should be implemented to listen for a button action event. [0.5] *A. ActionListener C. FocusListener E. ContainerListener B. MouseListener D. WindowListener 35 The method __________ sets the font (Helvetica, 20-point bold) in Graphics object g. [0.5] A. g.setFont(new Font("Helvetica", Font.bold, 20)) C. g.setFont(new Font("helvetica", BOLD, 20)) *B. g.setFont(new Font("Helvetica", Font.BOLD, 20)) D. g.setFont(Font("Helvetica", Font.BOLD, 20)) 36) The default layout out of a contentPane in a Frame is __________. [0.5] A. FlowLayout C. GridLayout *B.BorderLayout D. None of the above.
  7. 37) The default layout out of a Panel is __________. [0.5] *A. FlowLayout C. BorderLayout B. GridLayout D. None of the above. 38) Java applications and applets both __________. [0.5] A. have a main() method C. are executed from the HTML file B. are executed using the java *D. are compiled using the javac command command 39) The __________ method is executed when the page becomes inactive. [0.5] A. init() *C. stop() B. start() D. destroy() 40) To get the x coordinate of the mouse pointer for the MouseEvent evt, you use ____(choose 2). [0.5] *A. evt.getX() C. evt.X *B. evt.getPoint().x D. None of the above
Đồng bộ tài khoản