wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Mock test doubt? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Mock test doubt?" Watch "Mock test doubt?" New topic
Author

Mock test doubt?

swati cha
Ranch Hand

Joined: Jul 04, 2006
Posts: 40
Hi all,

can anyone explain the following code output....

import java.awt.*;
import java.awt.event.*;
public class MyWc extends Frame implements WindowListener{
public static void main(String argv[]){
MyWc mwc = new MyWc();
}
public void windowClosing(WindowEvent we){
System.exit(0);
}//End of windowClosing
public void MyWc(){
setSize(300,300);
setVisible(true);
}}//End of class

Thanks..
Mack Stevens
Greenhorn

Joined: Aug 31, 2007
Posts: 17
HI
When you are implementing WindowListener in your code you need to override all the abstract methods of WindowListener ,else you need to declare your class as abstract.
Alternative solution is to use extend WindowAdapter class which provides empty declarations for the abstract methods in WindowListener.
swati cha
Ranch Hand

Joined: Jul 04, 2006
Posts: 40
can we declare the main class as abstract?
madhu kancharla
Greenhorn

Joined: Jul 30, 2007
Posts: 14
hi swati

you can not declare main as abstract,
main is the starting point for the JVM to start execution of your program if
its abstract it wont even compile because definitely you will write block of code for that.
but remember abstract methods dont have method body
in fact main is the static method
dont make any static method as abstract its compiler error

hope its clear
swati cha
Ranch Hand

Joined: Jul 04, 2006
Posts: 40
Thanks for your reply
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Howdy "swati" !

Thanks for one of your first contributions to this forum and...

Welcome to the Ranch!




Hope you'll enjoy.




Only one small issue: The Java Ranch follows a certain policy regarding user names.
The main reasons why and a link how to change yours you'll find here:
http://www.javaranch.com/name.jsp


So, could you please change your user name before your next posting?
It will not affect anything you've already posted here. Just your user name will update.


I'm posting this because I am one of the moderators of this forum.


Yours,
Bu.


all events occur in real time
Mack Stevens
Greenhorn

Joined: Aug 31, 2007
Posts: 17
Hi.................
No you cant declare main as abstract
Solution:
Provide two classes for your application,one(having main method)extending Frame and other class extending WindowAdapter,because you cant extend two classes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mock test doubt?