21. what happens when you instantiate an object ?
When you create instance of a class using new operator foll happens-
New memory is allocated
instance is created on heap
reference is created on stack and passed on the the instantiated object.
22. What happens if "new" keyword fails while instantiating ?
it throws OutOfMemoryException.
23. What is default access modifier of constructor ?
24. Is it Ok to throw an exception from a constructor ?
No its not preferred. Constructors are used mainly for initialization purpose.but there are
certain .Net Framewrok classes like DateTime,FileStream et which throw exception from
25. In what instances you will declare a constructor to be private?
When we create a private constructor, we cannot create object of the class directly from a client.
Therefore, you will use private constructors when you do not want instances of the class to be
created by any external client. Example UTILITY functions in project will have no instance and
be used with out creating instance, as creating instances of the class would be waste of memory.
26. Define destructors.
A destructor is called for a class object when that object passes out of scope or is explicitly deleted.A destructors as the name implies is used to destroy the objects that have been created by a constructors.Like a constructor , the destructor is a member function whose name is the same as the class name but is precised by a tilde(~).