exam questions

Exam 70-483 All Questions

View all questions & answers for the 70-483 exam

Exam 70-483 topic 2 question 123 discussion

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

You have the following code (line numbers are included for reference only):

You need to ensure that new instances of Connection can be created only by other classes by calling the Create method. The solution must allow classes to inherit from Connection.
What should you do?

  • A. Option A
  • B. Option B
  • C. Option C
  • D. Option D
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️
The following list provides the main features of a static class:
Contains only static members.

✑ Cannot be instantiated.
✑ Is sealed.
✑ Cannot contain Instance Constructors.
Creating a static class is therefore basically the same as creating a class that contains only static members and a private constructor. A private constructor prevents the class from being instantiated.
Reference: Static Classes and Static Class Members (C# Programming Guide) https://msdn.microsoft.com/en-us/library/79b3xss3.aspx

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
kartal
Highly Voted 5 years, 11 months ago
Yes answer should be D A–>you get compile error at 05: can not create an instance of abstract class B–>static classes can not be inherited C–> class is inaccessible due to its protection level
upvoted 33 times
anutural
5 years, 4 months ago
Isn't it 'C'. that will restrict creating an instance of the class from outside so other classes must use the 'Create' method for it.
upvoted 3 times
...
...
dosper
Highly Voted 5 years, 10 months ago
correct is D
upvoted 30 times
...
Surda
Most Recent 4 years, 5 months ago
D is correct
upvoted 1 times
...
noussa
4 years, 5 months ago
The correct answer is D
upvoted 2 times
...
Max134
4 years, 5 months ago
Correct is D. Answer C generates a compiler error, you can check it here: https://dotnetfiddle.net/UI3P9G
upvoted 3 times
...
demoinq
4 years, 6 months ago
The only available option is D since in the case of C the constructor is inaccessible due to its protection level.
upvoted 2 times
...
HgstExam
4 years, 9 months ago
The only correct anwser is D: public class Connection { protected Connection() { } public static Connection Create() { return new Connection(); } } public class Connection2 : Connection { }
upvoted 2 times
...
Mona30
4 years, 10 months ago
D: protected
upvoted 3 times
...
ramfg
4 years, 10 months ago
A and B do not allow instantiation of Connection classes. The D allows instantiation of classes from derived classes. Therefore, the only valid option is C.
upvoted 1 times
...
DiegoB
4 years, 10 months ago
D, tested
upvoted 2 times
...
MrAnderson
5 years ago
D is Correct
upvoted 4 times
...
VladWork
5 years, 2 months ago
Answer is D
upvoted 6 times
...
whtvr
5 years, 3 months ago
Checked the solution in code, the answer must be D
upvoted 9 times
...
sscooter1010
5 years, 4 months ago
The right answer has to be D, since we need to be able to inherit from it.
upvoted 6 times
...
pgarq19
5 years, 5 months ago
The correct answer should be option D. Can't be C because (even if your class is public), having a private Constructor will affect its protection level and it will be accessible. Therefore, you won't be able to inherit from this class. This has been tested. Also, A and B are discarded for the same reasons presented already.
upvoted 8 times
pgarq19
5 years, 5 months ago
Sorry. I meant: "...its protection level and it will be inaccessible..."
upvoted 2 times
...
...
elbaidwan
5 years, 5 months ago
Correct answer: C private constructor is accessible in its own class where defined. A class with private constructor cannot be inherited by other classes. ... protected constructor can be accessed from its own class, its subclasses, all other classes belonging to the same package and subclasses of other packages.
upvoted 3 times
...
AntChekalin
5 years, 7 months ago
C is the right answer. Class is still public, but it's constructor is privite^ so the only way you can call it - Static method
upvoted 7 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 ...