Rajesh Singh
What will be output of below code? public class MyClass{private MyClass(){}}class Program:MyClass{static void Main(string[] args){Console.WriteLine("Hello");Console.ReadLine();}}
By Rajesh Singh in .NET on Jan 09 2016
  • Bhuvanesh Mohankumar
    May, 2016 30

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

    • 2
  • Omprakash
    Jun, 2016 11

    Hello

    • 0
  • 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