Skip to main content

Hi guys can you please help me on this

2 replies [Last post]
shueishalee
Offline
Joined: 2012-12-13
Points: 0

I am new to the world of java.
I am struck with a small problem in a java code.
I am using eclipse and JRE7

The following is the code.

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

public class Welcomer {
private String welcome = "Hello!";
public void SayHello(){
System.out.println(welcome);
}
}

Here I get the error in Welcomer as "The public type Welcomer must be defined in its own file"

I don't understand what is the error.Kindly solve the problem and tell me whe
where I am making the mistakes.

Thanks in advance.Looking for your valuable suggestion.s

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
shueishalee
Offline
Joined: 2012-12-13
Points: 0

shueishalee wrote:
I am new to the world of java.
I am struck with a small problem in a java code.
I am using eclipse and JRE7

The following is the code.

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

public class Welcomer {
private String welcome = "Hello!";
public void SayHello(){
System.out.println(welcome);
}
}

Here I get the error in Welcomer as "The public type Welcomer must be defined in its own file"

I don't understand what is the error.Kindly solve the problem and tell me whe
where I am making the mistakes.

Thanks in advance.Looking for your valuable suggestion.s

mortezaadi
Offline
Joined: 2012-02-12
Points: 0

Put the Welcomer inside the SimpleApplication class or
in its own file.
you can not define two seperate class in a file! except for nested class ( which is a class INSIDE the other class)

Ex:

SimpleApplication.java --> public class SimpleApplication {
....
}
Welcomer.java --> public class Welcomer {
.....
}
or simply:

public class SimpleApplication {
....
public class Welcomer {
.....
}
}