• Post Reply Bookmark Topic Watch Topic
  • New Topic

Could someone please tell me why this 2nd class will not work?  RSS feed

 
Doug Woodin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


RetailSales.java:291: error: '{' expected
public class  SalesCalculation()
                              ^
1 error
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The compiler is pretty clear regarding the error. That is not the syntax for declaring a class. There is no parens (ie. '(' and ')' ), when declaring a class. It is expecting an '{' at that point.

Henry
 
Doug Woodin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I'm not even sure what this means.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doug Woodin wrote:
I'm not even sure what this means.


The error message is very clear...

Java Compiler wrote:class SalesCalculation is public, should be declared in a file named SalesCalculation.java


Java has a requirement that all java files declare only (at most) one public class, and that public class must match the name of the java file.

Henry
 
Doug Woodin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the idea is to have a multi class swing java file.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doug Woodin wrote:Well the idea is to have a multi class swing java file.


That's fine, but only one can be public. If you want more than one public class, then you need to define it in a separate java file.

Henry
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!