aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Please explain error message (Was: Information Message) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Please explain error message (Was: Information Message)" Watch "Please explain error message (Was: Information Message)" New topic
Author

Please explain error message (Was: Information Message)

Preetha Vasudevan
Ranch Hand

Joined: Sep 23, 2005
Posts: 33
when i run the following code i get an information in a window saying that class "sub" does not have a main method

code:

class super{
int a =10;
public int method(){
return a;
}
}
class sub extends super{
int a=15;
public int method() {
public int method(){
return a;
}
public static void main(string args[]) {
super x= new sub();
system.out.println(x.method());
}
}
according to my knowledge the class which contains the main method should be the name of the file.so i named the file as sub.java..so why this message.

please help!!
[ October 13, 2005: Message edited by: Barry Gaunt ]
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
i get an information in a window saying that class "sub" does not have a main method


The Java VM is looking for a method with this exact signature:

public static void main(String[] args)

Your main has a lowercase "String".

I see a few other problems too. You also have a lowercase 's' on "System.out.println()" method call. "super" is a reserved word and not a valid class name. The line declaring sub.method() is duplicated.

I'm not sure how the program was able to compile with these problems. Did you by chance retype your code into the post?

Also, it's a best practice to put only one class per source file. You should split super and sub into separate source files.

Make these changes and try to run it again.
Thomas Drew
Ranch Hand

Joined: Sep 15, 2004
Posts: 47
You should get an error on the class named super it is a keyword in java.
Preetha Vasudevan
Ranch Hand

Joined: Sep 23, 2005
Posts: 33
yes i retyped the code and corrected all my mistakes and my program has compiled and I got the expected result
'
Thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please explain error message (Was: Information Message)
 
Similar Threads
doubt in inheritance...
Please explain me the flow of this simple prog.......
why it displays wrongly?
Method Overloading
reg overriding