|
-
Jan 25th, 2007, 07:46 AM
#1
Thread Starter
New Member
Simple java (bluej) questions
(I am Dutch so it can be hard to understand )
1:
Are these two statements wrong or right? :
statement1: if (s1.equals (s2)) is true, is (s1 == s2) also true?
statement2: if (s1 == s2) is true, is (s1.equals (s2)) also true?
s1 and s2 are 2 objects with type String
2:
What are the rules for the expression behind a return statement.
3:
How can it be that when you call a method, there can be more then 1 method with the same name within one Class. Hoe can you see the difference between these two?
-
Jan 25th, 2007, 07:53 AM
#2
Frenzied Member
Re: Simple java (bluej) questions
== checks to see if both strings are the same object. .equals() compares the value.
How can it be that when you call a method, there can be more then 1 method with the same name within one Class. Hoe can you see the difference between these two?
return type and parameter list can be different.
-
Jan 25th, 2007, 07:57 AM
#3
Thread Starter
New Member
Re: Simple java (bluej) questions
Hey man, thanks for the quick reply:
so statement 1 is right and statement 2 is wrong?
greetz
-
Jan 25th, 2007, 10:20 AM
#4
Re: Simple java (bluej) questions
Yes.
As for question 2, the only rule is that the result is implicitly convertible to the return type of the containing method.
Regarding question 3, although the return type can be different in overloads, it is not part of the function signature and thus cannot be a distinguishing part of the overloading. In other words, you cannot have two methods that are identical except for their return type.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 26th, 2007, 06:39 PM
#5
Lively Member
Re: Simple java (bluej) questions
 Originally Posted by eddiemcm
Hey man, thanks for the quick reply:
so statement 1 is right and statement 2 is wrong?
greetz
You have it backwards.
"statement1: if (s1.equals (s2)) is true, is (s1 == s2) also true?"
I can have two Strings that contain the String "Lunchboxtheman" but that are both references to different objects, so this statement is false.
"statement2: if (s1 == s2) is true, is (s1.equals (s2)) also true?"
Assuming you are talking about Strings here, this statement is true. (s1 == s2) checks to see if s1 and s2 point to the same object, hence they contain the same data.
EDIT: spelling
Last edited by lunchboxtheman; Jan 26th, 2007 at 06:43 PM.
-
Jan 26th, 2007, 07:18 PM
#6
Re: Simple java (bluej) questions
I believe statement2 being wrong for any given object would be a violation of the contract for equals().
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|