This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock question

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic