Can we have private constructor in our class file. When we
are trying to create instance for the class will it create
or throw error regarding that?

Answer Posted / ranjeet saini

it does not throw an exception
bcoz we can create private constructor if we have static member in class
in this we can create a reference object with the help of static method.
class A
{
private A()
{
C.w.l(" Hi");
}
public static display()
{
return new A();
}
S V M ( S[] args)
{
A a=a.display()
}

}

Is This Answer Correct ?    1 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can partial class be inherited?

699


What is xor operator in c#?

722


Is null empty or whitespace c#?

730


1. Describe page life cycle?

1840


How do I run managed code in a process?

729


Can hashset contain duplicates c#?

680


Why we use extension method in c#?

699


Difference between abstract classes and interfaces

753


How many dimensions can an array have?

665


What is using directive in c#?

765


What operators can be used to cast from one reference type to another without the risk of throwing an exception?

707


Do events have return type c#?

713


explain Garbage collector’s functionality on unmanaged code

719


What are the namespace level elements?

698


What language is c# similar to?

705