aspose file tools*
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
Author

Mock question

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi!
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);
setVisible(true);
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
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
Sheriff

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.
Jason
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.
Thanks
------------------
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: http://aspose.com/file-tools
 
subject: Mock question