Quiz 10
Wednesday
With a piece of paper, write down your name and answers to the following questions.
There are exceptions that inherit from the
Error
class or theRuntimeException
class. What are these exceptions called?- unrecoverable exceptions
- unchecked exceptions
- recoverable exceptions
- checked exceptions
Is the following statement correct, and why?
IOException
serves as a superclass for exceptions that are related to programming errors, such as an out-of-bounds array subscript.Answer: False,
RuntimeException
serves as a superclass for exceptions that are related to programming errors, such as an out-of-bounds array subscript.Find and correct the error in the following code.
// create my own exception class by // deriving it from the Exception class. class MyException { public MyException(String message) { super("My Exception: " + message); } }
Correction:
// create my own exception class by // deriving it from the Exception class. class MyException extends Exception { public MyException(String message) { super("My Exception: " + message); } }
With the following class definitions...
class ClassA { public ClassA() {...} public void method1() {...} } class ClassB extends ClassA { public ClassB() {...} public void method1() {...} } class ClassC extends ClassB { public ClassC() {...} public void method1() {...} }
Are the following statements correct?
Answer: Yes
ClassA item = new ClassC(); item.method1();
If yes, which
method1
will be executed?- the one defined in
ClassA
- the one defined in
ClassB
- the one defined in
ClassC
- the one defined in
Student Performance and Statistics
A histogram of student performance on percentage grades for Quiz 10 on Wednesday.
A table showing the average performance for each question in Quiz 10 on Wednesday.
Friday
With a piece of paper, write down your name and answers to the following questions.
What method do you use to make a text field,
JTextField
, read-only?setChangeable(false)
setEditable(false)
setReadOnly(true)
setUneditable(true)
Which of the following is the name of a small box that contains text and appears when the mouse is hovered over a component.
- mnemonic
- pop-up help
- instance message
- tool tip
Describe what the following program does.
What is displayed in the window?
The window it titled as “Quiz #10 Question #4”. The window contains a button with text “Button” and a text area.
What happens when the button is pressed?
When the button is clicked, a new line of text, “Hello”, is appended to the text area.
import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.SwingUtilities; import javax.swing.WindowConstants; public final class Program implements Runnable { public static void main(String[] args) { SwingUtilities.invokeLater(new Program()); } @Override public void run() { final MainWindow window = new MainWindow(); window.setVisible(true); } } final class MainWindow extends JFrame { JButton button = new JButton("Button"); JTextArea area = new JTextArea(20, 20); public MainWindow() { super("Quiz #10 Question #4"); this.setLayout(new FlowLayout()); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.add(this.button); this.add(this.area); this.pack(); this.button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final String oldText = MainWindow.this.area.getText(); MainWindow.this.area.setText(oldText + "Hello\n"); } }); } }
Student Performance and Statistics
A histogram of student performance on percentage grades for Quiz 10 on Friday.
A table showing the average performance for each question in Quiz 10 on Friday.