1 / 32

F27SB2 Programming Languages

F27SB2 Programming Languages. Multiple Choice Questions. Introduction. these questions are from: Y. Daniel Liang, Introduction to Java Programming, Ninth Edition http://www.cs.armstrong.edu/liang/intro9e/test.html

clay
Download Presentation

F27SB2 Programming Languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. F27SB2 Programming Languages Multiple Choice Questions

  2. Introduction • these questions are from: • Y. Daniel Liang,Introduction to Java Programming, Ninth Edition • http://www.cs.armstrong.edu/liang/intro9e/test.html • thanks to Hind Zantout for locating the source and selecting appropriate questions • please note that: • some questions have multiple correct answers • our exam is not based on this source of questions

  3. Chapter 12 5 Which component cannot be added to a container? A. JPanel B. JButton C. JFrame D. JComponent

  4. Chapter 12 6 Which of the following are subclasses of java.awt.Component? A. Container classes B. Swing user interface classes C. Helper classes such as Color and Font D. Layout managers

  5. Chapter 12 12 Which of the following classes are in the java.awt package? A. Color B. Font C. Component D. JFrame E. JComponent

  6. Chapter 12 15 Analyze the following code....public class Test {public static void main(String[] args) {JFrame frame = new JFrame("My Frame");frame.add(new JButton("OK"));frame.add(new JButton("Cancel"));...} } A. Only button OK is displayed. B. Only button Cancel is displayed. C. Both button OK and button Cancel are displayed and button OK is displayed on the left side of button OK. D. Both button OK and button Cancel are displayed and button OK is displayed on the right side of button OK.

  7. Chapter 12 16 How many frames are displayed?public class Test {public static void main(String[] args) {JFrame f1 = new JFrame("My Frame");JFrame f2 = f1;JFrame f3 = f2;f1.setVisible(true);f2.setVisible(true);f3.setVisible(true);} } A. 1. B. 2. C. 3. D. 0.

  8. Chapter 12 20 Analyze the following code:public class Test1 extends JFrame {public Test1() {JButton jbt1 = new JButton("OK");add(jbt1);jbt1 = new JButton("Not OK");}public static void main(String[] args) {JFrame frame = new Test1();... } } A. The program displays nothing. B. The program displays a button with text OK. C. The program displays a button with text Not OK. D. The program displays a button with text OK and another button with text Not OK.

  9. Chapter 12 21 What layout manager should you use so that every component occupies the same size in the container? A. a FlowLayout B. a GridLayout C. a BorderLayout D. any layout

  10. Chapter 12 22 What should you use to position a Button within an application Frame so that the size of the Button is NOT affected by the Frame size? A. a FlowLayout B. a GridLayout C. the center area of a BorderLayout D. the East or West area of a BorderLayout E. the North or South area of a BorderLayout

  11. Chapter 12 26 To set a FlowLayout in panel jp, you can use the method __________. A. jp.setLayout(new FlowLayout()); B. jp.setLayout(new FlowLayout(FlowLayout.CENTER)); C. jp.setLayout(new FlowLayout(FlowLayout.center)); D. jp.setLayout(FlowLayout

  12. Chapter 12 27 The default layout out of a contentPane in a JFrame is __________. A. FlowLayout B. GridLayout C. BorderLayout D. None

  13. Chapter 12 28 The default layout out of a JPanel is __________. A. FlowLayout B. GridLayout C. BorderLayout D. None

  14. Chapter 12 29 To create a JPanel of the BorderLayout, use ______________. A. JPanel p = new JPanel() B. JPanel p = new JPanel(BorderLayout()); C. JPanel p = new JPanel(new BorderLayout()); D. JPanel p = new JPanel().setLayout(new BorderLayout());

  15. Chapter 12 30 To add a component c to a JPanel p, use _________. A. p.add(c) B. p.getContentPane(c) C. p.insert(c) D. p.append(c)

  16. Chapter 12 32 The method __________ sets the background color to yellow in JFrame f. A. setBackground(Color.yellow) B. f.setBackground(Color.YELLOW) C. f.setBackground(Color.yellow) D. setBackground(Color.YELLOW) E. f.setBackGround(Color.yellow)

  17. Chapter 12 33The method __________ sets the foreground color to yellow in JFrame f. A. setForeground(Color.yellow) B. f.setForeground(Color.YELLOW) C. f.setForeground(Color.yellow) D. setForeground(Color.YELLOW) E. f.setForeGround(Color.yellow)

  18. Chapter 12 35 The method __________ sets the font (Helvetica, 20-point bold) in component C. A. c.setFont(new Font("Helvetica", Font.bold, 20)) B. c.setFont(new Font("helvetica", BOLD, 20)) C. c.setFont(Font("Helvetica", Font.BOLD, 20)) D. c.setFont(new Font("Helvetica", Font.BOLD, 20))

  19. Chapter 12 37 Can you use the setBackground method to set a back ground color for _____? A. Component B. Container C. JComponent D. JButton E. JLabel

  20. Chapter 12 43 You can use methods ___________ on any instance of java.awt.Component. A. setForeground B. setBackground C. setFont D. getFont E. setLayout

  21. Chapter 12 47 The method __________ gets the text (or caption) of the button jbt. A. jbt.text() B. jbt.getText() C. jbt.findText() D. jbt.retrieveText().

  22. Chapter 12 64 The method __________ assigns the name Result to the Text of variable jlbl. • A. jlbl.setText("Result") • B. jlbl.newText("Result") • C. jlbl.text("Result") • D. jlbl.findText()

  23. Chapter 16 1 Pressing a button generates a(n) __________ event. A. ItemEvent B. MouseEvent C. MouseMotionEvent D. ActionEvent E. ContainerEvent

  24. Chapter 16 2 Clicking the closing button on the upper-right corner of a frame generates a(n) __________ event. A. ItemEvent B. WindowEvent C. MouseMotionEvent D. ComponentEvent E. ContainerEvent

  25. Chapter 16 6 Which of the following statements registers a panel object p as a listener for a button variable jbt? A. addActionListener(p); B. jbt.addActionListener(p); C. jbt.addActionEventListener(p); D. jbt.addEventListener(p);

  26. Chapter 16 7 The interface __________ should be implemented to listen for a button action event. A. MouseListener B. ActionListener C. FocusListener D. WindowListener E. ContainerListener

  27. Chapter 16 33 To be a listener for ActionEvent, an object must be an instance of ____________. A. ActionEvent B. ActionListener C. EventObject D. WindowListener E. WindowEvent

  28. Chapter 17 1 Clicking a JButton object generates __________ events. A. ActionEvent B. ItemEvent C. ComponentEvent D. ContainerEvent

  29. Chapter 17 4 Pressing the Enter key on a JTextField generates _____________ events. A. ActionEvent B. ItemEvent C. ComponentEvent D. ContainerEvent

  30. Chapter 17 5 The method __________ appends a string s into the text area jta. A. jta.setText(s) B. jta.appendText(s) C. jta.append(s) D. jta.insertText(s)

  31. Chapter 17 7 To wrap a line in a text area jta, invoke ____________. A. jta.setLineWrap(false) B. jta.setLineWrap(true) C. jta.WrapLine() D. jta.wrapText()

  32. Chapter 17 9 The method __________ adds a text area jta to a scrollpanejScrollPane. A. jScrollPane.add(jta) B. jScrollPane.insert(jta) C. jScrollPane.addItem(jta) D. None of the above.

More Related