File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Sun Sample question: 8 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Sun Sample question: 8" Watch "Sun Sample question: 8" New topic

Sun Sample question: 8


Joined: Sep 19, 2000
Posts: 7
Sample question 8 from sun at the following URL

1. import java.awt.*;
3. public class Test extend Frame {
4. public Test() {
5. add( new Label("Hello") );
6. add( new TextField("Hello") );
7. add( new Button("Hello") );
8. pack();
9. show();
10. }
11. public static void main(String args[]) {
12. new Test();
13. }
What is the result?
A. The code will not complile.
B. A window will appear containing only a Button.
C. An IllegaArgumentException is thrown at line 6.
D. A window will appear but will not contain the Label, TextField, or Button.
E. A window will appear containing a Label at the top, a TextField below the Label, and a Button below the
F. A window will appear containing a Label on the left, a TextField to the right of the Label, and a Button to the
right of the TextField .

Answer given is:
B.A window will appear containing only a Button.
Since on line 3, the keyword is "extend" instead of "extends",
program should not compile. Any thoughts???
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
It doesn't compile as written, for the very reason you cited.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
I agree. Here's the link:
subject: Sun Sample question: 8
It's not a secret anymore!