FHTW Berlin |
A Meeter/Greeter is someone who has been appointed to stand at the door of an establishment like a church or a store and make people feel that they are welcome. Why anyone in their right mind would feel welcome just because someone with a fake smile is shaking their hands is beyond me, but maybe that will help you do the exercise 1. Work in groups of two!
Consider the following definition:
public class MeeterGreeter
{
private
String greeterName;
public MeeterGreeter( String name )
{
this.greeterName
= name;
}
public void sayHello()
{
Console.println( "Hello,
I'm " + this.greeterName );
}
public void sayHello( String toWhom
)
{
Console.println( "Hello, " + toWhom
+ ", I'm "
+ this.greeterName );
}
public String getNameWithIntroduction ( String
toWhom )
{
// ****
this.sayHello( toWhom );
return this.greeterName;
}
}
Now assume that the following definition is executed:
MeeterGreeter pat
= new MeeterGreeter( "Pat" ),
terry = new MeeterGreeter( "Terry"
);
pat.sayHello()
?
What is returned? Which method is invoked?new
MeeterGreeter( "Chris" ).sayHello( "Terry" )
? What
is returned? Which method is invoked?terry.sayHello(
"Pat" )
? What is returned? Which method is invoked?pat.getNameWithIntroduction( "Chris" )
is being evaluated. What would the value be of each of the following expressions
if they were to appear on the ****'d line: toWhom
2. this.greeterName
3. name
4. this.sayHello()
5. new MeeterGreeter(
"Pat" )
6. this.getNameWithIntroduction( toWhom );
private
static String greeting = "Hello"
;changeGreeting
method that allows a user to change the greeting string.sayHello
methods to replace the fixed string "Hello"
with the a reference to the greeting field. Whose greeting field is it?rememberAndReturnPrevious
, that takes a String and returns
the String it was previously given. Supply the first return value through the
instance creation expression. Give an example of your code in use.
The
exercise for next week is an experiment, note that you will need to prepare some
finger exercises!