• Post Reply Bookmark Topic Watch Topic
  • New Topic

java Method overloading  RSS feed

 
daniel kidanee
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am trying to do the following exercise but I keep getting errors, can any one help me
what my mistake is thanks!

The class Overloading below asks for two names and prints three different greetings. Your task is to write the class methods missing from the class declaration. Methods print the greetings as shown in the example print.

Hint:The names and parameter types of the needed methods can be checked from the main method because all methods are called there. This exercise also does not require you to copy the source code below to the return field. The method declarations will suffice.
Example output
Type in the first name: John
Type in the second name: Doe

**********
Hi!
**********
Hi, John
**********
Hi, John and Doe
**********

 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have to give us more info. What are the errors you are seeing? Are they compiler errors, run-time errors...what?

Make it easy for us to help you by posting all the details.
 
daniel kidanee
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
It is a compiler error, as follows:


^

 
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
daniel kidanee wrote:Hi,
It is a compiler error, as follows:



When declaring method parameters, you have to specify the type.

Henry
 
daniel kidanee
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hennry,
Can you give me an example for lets say the second class?
I tried to declare but I guess I am missing a basic concept
thanks,
 
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
daniel kidanee wrote:Hi Hennry,
Can you give me an example for lets say the second class?
I tried to declare but I guess I am missing a basic concept
thanks,


What second class are you referring to?

Henry
 
daniel kidanee
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi hennry, the following is what I meant.

private static void greet(firstName){

System.out.println("Hi, "+firstName);


}
 
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
daniel kidanee wrote: Hi hennry, the following is what I meant.

private static void greet(firstName){

System.out.println("Hi, "+firstName);


}



That's a method -- not a class. And as already mentioned, when defining parameters, you need to declare the parameter type. What type of variable is firstName? Is it an int? a double? a String? The compiler can't read your mind -- even though the type may be obvious.

Henry
 
daniel kidanee
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I did try it putting string to firstNane, do you see any other problem in
the three class methods?
thanks
 
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
daniel kidanee wrote:hi,
I did try it putting string to firstNane, do you see any other problem in
the three class methods?
thanks


Before you start looking for any other problems, shouldn't you fix the one that the compiler is complaining about first?

What "putting string to firstName" are you referring to? Are you saying that you tried to add the type to the declaration and it still didn't work? If so, show us what you tried.

Henry
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!