The quiz will cover all of Chapter 8 (testing) and all of Chapter 9 (class extension). You will not have to write any code. You may have to describe what code that I give you does. It will be closed book.
Sample quiz questions (and answers):
public class B extends A { ...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Demo extends JApplet implements ActionListener {
private Display disp = new Display();
public void init() {
setLayout(new FlowLayout());
add(disp);
JButton button = new JButton("push me");
add(button);
button.addActionListener(this);
} // end of init method
public void actionPerformed(ActionEvent event) {
disp.act();
} // end of actionPerformed method
} // end of Demo class
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Display extends JPanel {
private boolean show = true;
public Display() {
setPreferredSize(new Dimension(200,200));
setBackground(Color.white);
} // end of constructor
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (show) {
g.setColor(Color.black);
g.fillOval(0,0,200,200);
}
} // end of paintComponent method
public void act() {
show = !show;
repaint();
} // end of act method
} // end of Display class
What is displayed when the applet begins and before the button is pushed?
What happens every time the button is pushed.
public class Alpha extends Beta { ...
Which, Alpha or Beta, is the subclass?
Which, Alpha or Beta, is the superclass?
Solutions:
When the button is pushed the first time the black circle disappears (leaving just the white square). When the button is pushed again the black circle reappears. Successive button pushes cause the circle to disappear, appear, disappear, appear, etc.