Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please explain error message (Was: Information Message)

 
Preetha Vasudevan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should get an error on the class named super it is a keyword in java.
 
Preetha Vasudevan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i retyped the code and corrected all my mistakes and my program has compiled and I got the expected result
'
Thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic