Skip to main content

Hi guys i need help on this.

1 reply [Last post]
Joined: 2012-12-13

I am new to java.Can you please help me.

I am using eclipse and I am getting an error in the below code.

Please reply me with correct solution for this.

public class SimpleApplication {
public static void main(String[] args) {
Welcomer welcomer = new Welcomer();

public class Welcomer {
private String welcome = "Hello!";
public void SayHello(){

And also tell me where is the error has occurred.when I compile I get this error
"The public type Welcomer must be defined in its own file"

Thanks in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2008-03-28

you are limited in java to one public class per file. The filename must match the classname. This allows the jvm to easily locate classes based on the filenames only.

You can:
create another class file for the Welcomer class
make the Welcomer class private (only accessible by SimpleApplication).