Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock test doubt?

 
swati cha
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we declare the main class as abstract?
 
madhu kancharla
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mack Stevens
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic