Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

Exam 98-361 topic 1 question 104 discussion

Actual exam question from Microsoft's 98-361
Question #: 104
Topic #: 1
[All 98-361 Questions]

HOTSPOT -
You are reviewing the following class that is used to manage the results of a 5K race:

For each of the following statements, select Yes if the statement is true. Otherwise, select No. Each correct selection is worth one point.
Hot Area:

Show Suggested Answer Hide Answer
Suggested Answer:

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
cdc
Highly Voted 4 years, 10 months ago
Yes, Yes, No
upvoted 10 times
Hashino
4 years, 2 months ago
i believe the answer to the first one is Yes, although you could technically change the value after it had already been set, the intention of the code is clearly for that to be impossible, and the technique pointed out by Difdoor (there may be others) seems too advanced for the scope of this exam. side note: defining only a get would ensure that the property _name can only be set in the constructor. private string _name { get; } and there are more robust ways to also ensure the consistency of a property than if(_name != null) that should also be used alongside this approach.
upvoted 1 times
...
...
Birdy
Highly Voted 4 years, 9 months ago
Why the second statement is YES? Why MatchName method should throw an exception?
upvoted 6 times
Lets123
3 years, 4 months ago
Because name has null value
upvoted 2 times
...
...
oneup
Most Recent 2 years, 11 months ago
- You can change Key from "player" to "racer" Key is a constant so you can't change that value, that's clear. But the other two answers are debatable: - You can only set the players ranking once. That depends, if the name was previously set by passing it to the SetResult() method you can only set it once, but if you pass null to the "name" argument of SetResult() you can set it as many times as you want. - If you call the MatchName method, the code will throw an exception. That also depends on whether or the name was set using SetResult(). If it wasn't MatchName() will throw a NullPointerException, but if the name has been set that method will not throw an exception.
upvoted 2 times
...
vinx909
2 years, 12 months ago
wouldn't this be yes, no, no? MatchName can trow an exception if name is not set, but we don't have the code where it's called so we don't know if the name is not set. it will always return false because == is not the correct tool to use for strings, but it's not guaranteed to throw an exception. (also isn't ranking set at any time SetResults is called?)
upvoted 1 times
...
Kisima
3 years, 2 months ago
Mwita Zabron yes, yes,no
upvoted 2 times
...
Pomphard
3 years, 6 months ago
As for the first question, it is obviously meant to be impossible to set the ranking twice, however doing so multiple times is way easier than Difdoor's suggesting: You just have to pass null as a name and don't need any exception handling to pass multiple rankings. For the second question: Of course the bool MatchName won't throw an exception if there is a name present. However, if no name has been passed using SetResult yet it will throw a NullReferenceException. Question 3 is a no-brainer, consts cannot be changed. All in all this is a terrible question with a lot of speculation possible. In the end I think they want us to answer 'Yes, No, No'. I rewrote the class and ran the following snippet to fact-check my speculations: Player player = new Player(); player.SetResult(5, null); player.SetResult(10, "Foo"); player.SetResult(15, "Will return"); Console.WriteLine(player.Ranking); Console.WriteLine(player.MatchName("foo")); Returns: 10 True
upvoted 2 times
...
Difdoor
4 years, 8 months ago
On question 1, I think you could reset the Ranking but only if you initially called SetResult with an int and a null string which (I think) would throw an exception after assigning the rank. You would need to catch this exception and then call SetResult with valid values resetting the values of rank and name. (Very contrived but you almost always call SetResult in a try-catch.) So No for question 1.
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...