Rajesh Singh
What will be output of below code?
  1. public class MyClass
  2. {
  3. private MyClass(){}
  4. }
  5. class Program:MyClass
  6. {
  7. static void Main(string[] args)
  8. {
  9. Console.WriteLine("Hello");
  10. Console.ReadLine();
  11. }
  12. }
By Rajesh Singh in .NET on Jan 09 2016
  • Bhuvanesh Mohankumar
    May, 2016 30

    Constructor -> private MyClass() cannot be inherited Program:MyClass

    • 2
  • Shivanand Baste
    Mar, 2016 23

    Myclass is not accessible because of protection level.. when class has private constructor it can not inheritable.. if you want to inherit Myclass then you must need to add one public constructor with parameter then you can create object of MyClass.

    • 0
  • Pankaj  Kumar Choudhary
    Feb, 2016 21

    Error Because A class having private constructor cannot be inherited or instantiated.

    • 0
  • Ashish Kumar Jaiswal
    Jan, 2016 16

    Error I because ClassWithPvtConstructor cannot be declare as private

    • 0
  • Anil Kumar Murmu
    Jan, 2016 12

    it can not be inherited however, we can instantiate it using parameterized constructor.class Program{static void Main(string[] args){ClassWithPvtConstructor classWithPvtConstructor = new ClassWithPvtConstructor("parameter1");classWithPvtConstructor.a = 30;Console.WriteLine("Value of a is {0}", classWithPvtConstructor.a);Console.ReadKey();}}public class ClassWithPvtConstructor{public int a = 0;private ClassWithPvtConstructor(){Console.WriteLine("This is a private constructor.");}public ClassWithPvtConstructor(string strInput){Console.WriteLine("This is a private constructor with Parameter " + strInput);}}

    • 0
  • Rajesh Singh
    Jan, 2016 9

    Ans: Compile time errorDesc: MyClass has private constructor. A class having private constructor cannot be inherited or instantiated.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS