70-483 question 200 discussion


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
Created 5 months, 3 weeks ago by visionapp.development


D is the correct answer. If you set the class Connection as static, you can't create any instances of the class.


The solution must allow classes to inherit from Connection, you can't inherit from static class, So D is not correct


if you do not want class Connection to be instantiated outside class Connection, then it should be private Connection(){}


"The solution must allow classes to inherit from Connection." This requires base constructor to be protected to allow Derived class access. However, this introduces a new problem. Default created constructors are always public, so now we are allowed to do new Derived(). To only allow instance cration through the factory methods we need to remember constructors protected also for sub-classes.