exam questions

Exam 70-483 All Questions

View all questions & answers for the 70-483 exam

Exam 70-483 topic 1 question 25 discussion

Actual exam question from Microsoft's 70-483
Question #: 25
Topic #: 1
[All 70-483 Questions]

DRAG DROP -
You are developing an application that includes a class named Kiosk. The Kiosk class includes a static property named Catalog. The Kiosk class is defined by the following code segment. (Line numbers are included for reference only.)

You have the following requirements:
✑ Initialize the _catalog field to a Catalog instance.
✑ Initialize the _catalog field only once.
✑ Ensure that the application code acquires a lock only when the _catalog object must be instantiated.
You need to meet the requirements.
Which three code segments should you insert in sequence at line 09? (To answer, move the appropriate code segments from the list of code segments to the answer area and arrange them in the correct order.)
Select and Place:

Show Suggested Answer Hide Answer
Suggested Answer:
After taking a lock you must check once again the _catalog field to be sure that other threads didn't instantiated it in the meantime.

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
patoyanez
Highly Voted 5 years, 10 months ago
maybe: if(_catalog == null) lock(_lock) if(catalog == null) _catalog = new Catalog(); link: https://docs.microsoft.com/en-us/previous-versions/msp-n-p/ff650316(v=pandp.10)
upvoted 58 times
tanujgyan
4 years, 8 months ago
This is the correct answer
upvoted 4 times
...
...
Oziriz
Highly Voted 5 years, 11 months ago
Answer options don't show and correct answer is wrong?
upvoted 7 times
...
rubendlrg
Most Recent 3 years, 10 months ago
Here is the full question https://www.freecram.com/question/Microsoft.70-483.v2018-03-20.q120/drag-drop-you-are-developing-an-application-that-includes-a-class-named-kiosk-the-kiosk-class-includes
upvoted 1 times
...
ellyg
3 years, 10 months ago
i'm confused @patoyanez
upvoted 1 times
...
Xzibit23
4 years, 6 months ago
I would only use if(_catalog==null){ _catalog = new Catalog(); } this is not an async method, so why would you place the lock in there? makes no sense..
upvoted 2 times
SebastianB
4 years ago
It isn't about asynchronicity, but about thread safe.
upvoted 3 times
...
...
TonyBezerra
4 years, 9 months ago
I think the rigth answer is: if(_catalog != null) lock(_lock); if(_catalog == null) _catalog = new Catalog();
upvoted 3 times
tanujgyan
4 years, 8 months ago
This is not right you have to acquire the lock only if _catalog is null. Answer by patoyanez is the correct answer
upvoted 3 times
SamarHussain
4 years, 2 months ago
Youre wrong. TonyBezerra's answer is correct. The 3rd requirement says "Ensure that the application code acquires a lock only when the _catalog object must be instantiated." Means you have to acquire the lock only if _catalog is instantiated (means not null). patoyanez answer is incorrect.
upvoted 3 times
Kilsimon
4 years, 2 months ago
If you write TonyBezerra's code, you would never initialize the _catalog field. First you check if it is not null, then you check if it is null. Unless it have changed while you were getting the lock, it would never enter the second if statement. _catalog cannot be both null and not null at the same time. I also think patoyanez have the correct answer to this question.
upvoted 4 times
...
...
...
...
whtvr
4 years, 9 months ago
Seems from the description it should be a simple Singleton example, so the answer from patoyanez should be correct
upvoted 1 times
...
LAV
5 years, 1 month ago
Correct answer: lock(_lock) if(_catalog==null) _catalog = new Catalog();
upvoted 2 times
LAV
5 years, 1 month ago
Sorry, i loose. Need add in first line if(_catalog==null)
upvoted 3 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 ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago