What is a private Constructor? When it is used?
A private constructor is a special instance constructor which can be used in classes that contain only static methods, one way of restricting instantiation.
The answer is No. We cannot unit test a private method.
public class MyClass {
///
}
public static MyClassExtensions {
public static MyClass DoExtended(this MyClass obj, int someparam1, int someparam2.. )
{
// do something
return obj;
}
}
MyClass obj = new MyClass();
obj.DoExtended(); // this works although DoExtended is not a part of MyClass
(function () {
let k = 1;
function kd() {
console.log(`value of k is ${k}`);
}
kd();
})();
output:
value of k is 1
function outer() {
let counter = 0;
function inner() {
counter++;
return counter;
}
return inner;
}
let instance = outer();
console.log(instance());
console.log(instance());
console.log(instance());
output:
1
2
3