It's not a secret anymore!
The moose likes Beginning Java and the fly likes Why This Compiler Error? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why This Compiler Error?" Watch "Why This Compiler Error?" New topic

Why This Compiler Error?

Gary Farms

Joined: Jul 31, 2002
Posts: 12
When I run the following java program, I get a compiler error saying it expects a ; on the B() statement.
Why this compiler error: Here's the program:
[ Formatted code is often much easier to read and understand. I edited this message to surround code with [code] and [/code] UBB Tags in order to help preserve the code formatting. -ds ]
[ September 26, 2002: Message edited by: Dirk Schreckmann ]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
It looks like you were trying to define the constructor inside of the main method. You can't do that this way. The constructor for class B belongs outside of any method body.Making sense?

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
The constructor of B() is inside main()
I agree. Here's the link:
subject: Why This Compiler Error?
It's not a secret anymore!