Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
Location Chicago IL, USA

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

Mitsoshima
7 months, 4 weeks ago
Correct answer is: C A static class is sealed, so it can't be inherited. An abstract class can't be instanciated and the protected constructor allows instanciation by an inheriting class.
upvoted 7 times
...
kartal
7 months, 2 weeks 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 8 times
anutural
6 days, 19 hours 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 1 times
...
...
dosper
6 months, 1 week ago
correct is D
upvoted 10 times
...
AntChekalin
2 months, 4 weeks 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 3 times
...
elbaidwan
1 month 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 2 times
...
pgarq19
3 weeks, 2 days 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 1 times
pgarq19
3 weeks, 2 days ago
Sorry. I meant: "...its protection level and it will be inaccessible..."
upvoted 1 times
...
...
sscooter1010
2 weeks, 3 days ago
The right answer has to be D, since we need to be able to inherit from it.
upvoted 1 times
...

SaveCancel