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 Mock question 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 "Mock question" Watch "Mock question" New topic

Mock question

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
The correct answer is A. Why???
Thank you.
26. Which of the following are correct, if you compile the following code?
public class CloseWindow extends Frame implements WindowListener {
public CloseWindow() {
addWindowListener(this); // This is listener registration
setSize(300, 300);
public void windowClosing(WindowEvent e) {
public static void main(String args[]) {
CloseWindow CW = new CloseWindow();
A) Compile time error
B) Run time error
C) Code compiles but Frame does not listen to WindowEvents
D) Compile and runs successfully.

Jason Menard

Joined: Nov 09, 2000
Posts: 6450
The reason you get the error is that you didn't implement all the methods of the WindowListener interface. If you had instead extended WindowAdapter, there would be no error.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Jordi,
Would you please post the name of the Mock exam the question came from. It helps others who are working through the mocks.
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform

Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
I agree. Here's the link:
subject: Mock question
It's not a secret anymore!