1. Trang chủ
  2. » Giáo án - Bài giảng

Ôn thi tốt nghiệp JAVA and UML

153 542 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 153
Dung lượng 1,28 MB

Nội dung

Ôn thi t t nghi p: JAVA + UMLố ệ ( *** IN OOP (USING JAVA) SUBJECT *** ) Question 1–b A class Car and its subclass Yugo both have a method run() which was written by the programmer as part of the class definition. If junker refers to an object of type Yugo, what will the following code do? junker.show(); a) The compiler will complain that run() has been defined twice b)The show() method defined in Yugo will be called. b) The show() method defined in Car will be called. c) Overloading will be used to pick which run() is called Question 2–e A class design requires that a particular member variable must be accessible for direct access by any subclasses of this class, but otherwise not by classes which are not members of the same package. What should be done to achieve this? a) The variable should have no special access modifier b) The variable should be marked private and an accessor method provided c) The variable should be marked private d) The variable should be marked public e)The variable should be marked protected Question 3–d A Frame's background color is set to Color.Yellow, and a Button's background color is set to Color.Blue. Suppose the Button is added to a Panel, and the Panel is added to the Frame. What background color will be used with the Panel? a) Color.Green b) Color.Blue c) Color.White d) Color.Yellow Question 4–b A Java exception is an instance of __________. a) Exception b) Throwable. c) RuntimeException d) Error e) NumberFormatException Question 5–d A linked list that stores int values would be comprised(Bao gom) of a group of Nodes. We might define Node by a) class Node { int next; } b) class Node { int[ ] data; - 1 - Ôn thi t t nghi p: JAVA + UMLố ệ Node next; } c) class Node { Node next; } d) class Node { int data; Node next; } e) class Node { int data; } Question 6–d A statement for a constructor that invokes the no-args, default constructor in its superclass is: a) this.constructor(); b) descendent classes can not call constructors of their superclass. c) This d) super(); Question 7–c A traversal of the binary search tree in figure is given as: 12, 27, 25, 28, 20, 38, 45, 42, 35, 30 Determine one which of the following traversals has been performed a) Reverse PostOrder Traversal b) InOrder Traversal - 2 - Ôn thi t t nghi p: JAVA + UMLố ệ c) PostOrder Traversal d) Reverse PreOrder Traversal e) PreOrder Traversal Question 8–b A vector can be described as _______. a) A fixed length data structure b) A dynamic array c) A special type queue d) A special type of stack Question 9–d After execution of the code fragment below, what are the values of the variables x, a, and b? 1. int x, a = 6, b = 7; 2. x = a++ + b++; a) x = 13, a = 6, b = 7 b) x = 15, a = 6, b = 7 c) x = 15, a = 7, b = 8 d) x = 13, a = 7, b = 8 Question 10–c An aggregation relationship is usually represented as __________ in ___________. a) a data field/the aggregated class b) a method/the aggregated class c) a data field/the aggregating class d) a method/the aggregating class Question 11–de An instance of _________ are checked exceptions. a) Throwable. b) NumberFormatException c) Error d) RuntimeException e) Exception Question 12–e An instance of _________ describes programming errors, such as bad casting, accessing an out-of-bounds array, and numeric errors a) Error b) NumberFormatException c) Throwable. d) Exception e) RuntimeException Question 13–e An instance of _________ describes the errors caused by your program and external circumstances. These errors can be caught and handled by your program. a) Error - 3 - Ôn thi t t nghi p: JAVA + UMLố ệ b) RuntimeException c) Throwable. d) NumberFormatException e) Exception Question 14–c Analyze the following code: Circle c = new Circle (5); Cylinder c = cy; a) The code is fine. b) The code has a runtime error. c) The code has a syntax error. Question 15–a Analyze the following code: class Circle { private double radius; public Circle(double radius) { radius = radius; } } a) The program will compile, but you cannot create an object of Circle with a specified radius. The object will always have radius 0. b) The program has a compilation error because it does not have a main method. c) The program has a compilation error because you cannot assign radius to radius. d) The program does not compile because Circle does not have a default constructor. Question 16–d Analyze the following code: class Test { public static void main(String[] args) throws MyException { System.out.println("Welcome to Java"); } } class MyException extends Error { } a) You cannot declare an exception in the main method. b) The program has a compilation error. c) You declared an exception in the main method, but you did not throw it. d) You should not declare a class that extends Error, because Error raises a fatal error that terminates the program. Question 17–c Analyze the following code: - 4 - Ôn thi t t nghi p: JAVA + UMLố ệ class Test { public static void main(String[] args) { try { Integer.parseInt(5.6); // Cause a NumberFormatException int i = 0; int y = 2 / i; } catch (Exception ex) { System.out.println("NumberFormatException"); } catch (RuntimeException ex) { System.out.println("RuntimeException"); } } } a) The program displays RuntimeException. b) The program displays NumberFormatException. c) The program has a compilation error. d) The program displays NumberFormatException followed by RuntimeException. Question 18–c Analyze the following code: class Test { public static void main(String[] args) { try { int zero = 0; int y = 2/zero; try { Integer.parseInt(5.6); // Causes NumberFormatExcepiton } catch(Exception e) { } } catch(RuntimeException e) { System.out.println(e); } } } a) None of the other answers b) The program has a compilation error because Exception appears before RuntimeException. c) A good programming practice is to avoid nesting try-catch blocks, because nesting makes programs difficult to read. You can rewrite the program using only one try-catch block. - 5 - Ôn thi t t nghi p: JAVA + UMLố ệ d) A try-catch block cannot be embedded inside another try-catch block. Question 19–c Analyze the following code: class WhatHappens implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System.out.println("hi"); } } a) This program compiles and the word "hi' appears in the standard output, once b) This program compiles and the word "hi" appears continuously in the standard output until the user hits control-c to stop the program c) This program does not compile d) This program compiles but nothing appears in the standard output Question 20–a Analyze the following code: Cylinder cy = new Cylinder(1, 1); Circle c = cy; a) The code is fine. b) The code has a runtime error. c) The code has a syntax error. Question 21–e Analyze the following code. import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Test extends A { public static void main(String[] args) { A frame = new Test(); frame.setSize(200, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } JButton jbtOK = new JButton("OK"); public Test() { getContentPane().add(jbtOK); jbtOK.addActionListener(this); - 6 - Ôn thi t t nghi p: JAVA + UMLố ệ } public void actionPerformed(ActionEvent e) { super.actionPerformed(e); if (e.getSource() == jbtOK) System.out.println("OK button is clicked"); } } class A extends JFrame implements ActionListener { JButton jbtCancel = new JButton("Cancel"); public A() { getContentPane().setLayout(new FlowLayout()); getContentPane().add(jbtCancel); jbtCancel.addActionListener(this); } public void actionPerformed(ActionEvent e) { if (e.getSource() == jbtCancel) System.out.println("Cancel button is clicked"); } } a) When you click the OK button the message "OK button is clicked" is displayed. b) When you click the Cancel button the message "Cancel button is clicked" is displayed. c) The program displays Cancel button on the left of the OK button. d) If the super.actionPerformed(e) statement in the actionPerformed method in the Test class is omitted, no message is displayed if you click the Cancel button. e) All of the other answers Question 22–d Analyze the following code. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Test1 extends JFrame { public Test1() { getContentPane().add(new MyCanvas()); } public static void main(String[] args) { JFrame frame = new Test1(); frame.setSize(300, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } - 7 - Ôn thi t t nghi p: JAVA + UMLố ệ class MyCanvas extends JPanel { private String message; public void setMessage(String message) { this.message = message; } public void paintComponent(Graphics g) { super.paintComponent(g); g.drawString(message, 20, 20); } } a) The program has a syntax error because new Test1() is assigned to frame. b) The program would display Welcome to Java! if you replace new MyCanvas() by new MyCanvas("Welcome to Java!"). c) The program runs fine and displays nothing since you have not set a string value. d) The program has a NullPointerException since message is null when g.drawString(message, 20, 20) is executed. Question 23–d Analyze the following code: import javax.swing.*; import javax.swing.border.*; import java.awt.*; public class Test extends JFrame { public Test() { Border border = new TitledBorder("My button"); JButton jbt1 = new JButton("OK"); JButton jbt2 = new JButton("Cancel"); jbt1.setBorder(border); jbt2.setBorder(border); getContentPane().add(jbt1, BorderLayout.NORTH); getContentPane().add(jbt2, BorderLayout.SOUTH); } public static void main(String[] args) { JFrame frame = new Test(); frame.setSize(200, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } a) The program has a syntax error because you assign new TitledBorder("My button") to a variable of the Border type. b) The program has a runtime error because you cannot set a border on a button. c) Two buttons displayed, but only one button has the border. - 8 - Ôn thi t t nghi p: JAVA + UMLố ệ d) Two buttons displayed with the same border. Question 24–d Analyze the following code. import java.awt.*; import javax.swing.*; public class Test { public static void main(String[] args) { Component c = new JButton("OK"); JFrame frame = new JFrame("My Frame"); frame.add(c); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } a) You can only add c to a container because c's type is Component. b) You cannot create a JFrame using new JFrame("My Frame"). c) You cannot assign a JButton to a variable of java.awt.Component. d) You cannot add a Swing component directly to a JFrame. e) Instead, you have to add it to a JFrame's contentPane using frame.getContentPane().add(c). Question 25–e Analyze the following code. import java.awt.*; import javax.swing.*; public class Test { public static void main(String[] args) { JFrame frame = new JFrame("My Frame"); frame.getContentPane().add(new MyDrawing("Welcome to Java!")); frame.setSize(300, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.setVisible(true); } } class MyDrawing extends JPanel { String message; public MyDrawing(String message) { this.message = message; } public void paintcomponent(Graphics g) { super.paintComponent(g); g.drawString(message, 20 ,20); } } - 9 - Ôn thi t t nghi p: JAVA + UMLố ệ a) The program has a runtime error because the paintcomponent should be spelled as paintComponent. b) The program has a syntax error because the paintcomponent should be spelled as paintComponent. c) The program runs fine and displays Welcome to Java! d) It is a runtime to invoke the setVisible(true) twice. e) The program runs, but it does not display the message. Question 26–b Analyze the following code. import java.awt.*; import javax.swing.*; public class Test { public static void main(String[] args) { JFrame frame = new JFrame("My Frame"); frame.getContentPane().add(new JButton("OK")); frame.getContentPane().add(new JButton("Cancel")); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200); frame.setVisible(true); } } a) Both button OK and button Cancel are displayed and button OK is displayed on the left side of button OK. b) Only button Cancel is displayed. c) Both button OK and button Cancel are displayed and button OK is displayed on the right side of button OK. d) Only button OK is displayed. Question 27–b Analyze the following code: import javax.swing.*; import java.awt.*; public class Test extends JFrame { public Test() { getContentPane().setLayout(new FlowLayout()); getContentPane().add(new JButton("Java")); getContentPane().add(new JButton("Java")); getContentPane().add(new JButton("Java")); getContentPane().add(new JButton("Java")); } public static void main(String[] args) { // Create a frame and set its properties JFrame frame = new Test(); frame.setSize(200, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - 10 - [...]... following switch block: - 29 - Ôn thi tốt nghiệp: JAVA + UML char mychar = c; switch (mychar) { default: case 'a': System.out.println("a"); break; case b: System.out.println("b"); break; } Which of the following questions are definitely true? a) When this code runs, the letter "a" is written to the standard output b) When this code runs, nothing is writ en to the standard output c) This switch block is illegal,... Box class aBox and bBox are two reference variables to Box objects with the same height and width: - 17 - Ôn thi tốt nghiệp: JAVA + UML Box aBox = new Box(10, 40); Box bBox = new Box(10, 40); What is the result of evaluating (aBox == bBox) and why? a) true, because aBox and bBox refers to the same Box object b) not a valid boolean expression c) true, because aBox has the same height and width with.. .Ôn thi tốt nghiệp: JAVA + UML frame.setVisible(true); } } a) One button is displayed with the text "Java" b) Four buttons are displayed with the same text "Java" c) Three buttons are displayed with the same text "Java" d) Two buttons are displayed with the same text "Java" Question 28–b Analyze the following code: import javax.swing.*; public class Test extends... compile, and if method() is invoked, it writes 3 to the standard output e) Both classes compile, but if method() is invoked, it throws an exception Question 45–b Analyze this line of code: if(5 7 > 0 & 5|2) System.out.println("true"); a) this code will compile and write the word "true" in the standard output b) this line of code will not compile c) this code will compile but nothing will appear in the standard... 18 - Ôn thi tốt nghiệp: JAVA + UML // do something } Which one of the following is a correct way to call methodA? Assume data is a non-empty reference to an array object, and lbl is a non-empty reference to a JLabel object a) methodA( data, lbl); b) methodA( int [] data, lbl); c) methodA(data[], lbl); d) methodA( data[10], lbl); Question 51–a Assume the following method is properly synchronized and. .. void setSize(int iNewSize) { this.iSize = iNewSize; } } public class Main { - 23 - Ôn thi tốt nghiệp: JAVA + UML public static void main(String [] args) { GameComponent [] gc = new GameComponent [2]; gc[0] = new Ball(); gc[1] = new Paddle(); for (int i=0; i

Ngày đăng: 13/05/2014, 11:20

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w