Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

java Method overloading  RSS feed

 
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
**********

 
lowercase baba
Bartender
Posts: 12627
50
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:


^

 
author
Sheriff
Posts: 23571
138
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: 23571
138
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: 23571
138
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: 23571
138
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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!