OOPS interview questions and answers in C#.Net-part2

31)What is the need of copy constructor?

  -it is used to initialize new object with the help of an existing object when new object has been created.

32)What is destructor and when is it invoked?


    -it is also special method which is invoked automatically before object destruction takes place by Garbage collector.
   -the name of the destructor and the name of the class must be same.
   -it must be preceded by ~ character.
   -access modifiers can't be applied
   -It must be parameter less

33)What is disadvantage of destructor?


    -the destructor in the class is represented by finalize( )
    -when GC decide to deallocate the memory then it will check is there any finalize() defined for the object if so then the object will be moved to freechable queue.
    - finalize() of object is invoked which intern invokes finalize() of system.Object
    -finalize() of system.object invokes GC to deallocate memory,so that it ill be extra burdden to the GC when the destructor has been defined for the class.

34)When the class is loaded in to AppDomain?


   - the class can be loaded into the application domain in the following situations
    a)when the first object of the class has been created
    b)when the static method of the class has been invoked.

35)How to invoke base class constructor in Derived class constructor?

    - by using base Keyword.

36)What is namespace?

    -It is a logical container which can contain classes, interfaces, enums, deligates, structures
    -with the help of the namespace we can avoid name collisions.
    - A namespace can contain another name space also.

37)Can we apply access modifier to namespace?


    -No

38)Is it possible to declare instace variables in namespace?


   -No

39)What is alias name for namespace and when is it required?


  -While including too many namespaces in the application with the help of using keyword then there is a chance of duplicate members.
  - too avoid the conflict we can asign a temporary name to the duplicate member which is called as alias name for the namespace.

40)What is the difference between namespace and class?

   -namespace is logical container which can contain classes,interfaces,enums,structs...
    -members of namespace will be either public or internal
    -class is feature of language which is used to implement encasulation
    -all access modifiers are allowed on members of class

41)What is difference between  out and ref parameters?

    Out                                                                ref
  -it is write only varibale in method                 -it is read and write variable in method.
-it must be preceded by out keyword               -it must be preceded by ref keyword
-it need not to be initialized while passing it    -it must be initialized while passing to method.
  to method                                                        - changes are reflected
-Changes are reflected

42)What is the purpose  of params key word?


   - To pass the array of parameter to the method we can make use of  params Keyword.

43)What is binding?


  - Replacing the method invokation with its appropriate base reference is called as binding or linking

44)How many types of bindings are available?


  - Ther eare two types of binding
   a)Static Binding
        If the binding process has been carried out during the compilation then it is called as Static binding
   b)Dynamic Binding
        If the binding process has been carried out at the time of runing the application then it is called as dynamic binding

45)What is Method overloading?


     -defining number of methods with same name and different signatures is called as Method Overloading
     -Method Overloading is possible with in the same class as well as its derived classes.
     -Any types of methods can be Overloaded.
     -No Keyword must be required for the method.

46)What is Method overriding?


   -Defining number of method with same name, same signature and same return type with differnt functionality is called as method Overriding.
   -It is Possible with in the derived classes only
   -Only virtual and Abstract methods  only can be Overrided
  -override Keyword must be used.

47)What is difference between Method overloading and Method overriding?


48.What is polymorphism?

     - Having Diffrent forms to the same method is called as Polymorphism.
     -With the help of polymorphism we can perform different actions with same method invokation

49)What are the types of polymorphism?


     -There are two types of polymorphism
    a)static Polymorphism 
       - If the Polymorphism is implemented by using Static binding then it is Static Polymorphism
       -In C# Static polymorphism can be implemented by using method Overloading and operator Overloading
    b)Dynamic polymorphism
       -If polymorphism is implemented by using dynamic binding then it is called as Dynamic Polymorphism
       -In C# Dynamic polymorphism is implemented by using method Overriding

50)What is the difference between abstract class and interface?


 Abstract Class                                                               Interface
-It is Partially unimplemented class                             -Fully Unimplemented class
-Complete Abstraction is not Possible                         -Complete Abstraction is possible
-All Types of members are allowed                              -Only methods, Properties and indexes are allowed
-Object can not be created                                           -Object cant not be created
-Access modifier can be applied to the members         -Access modifiers can not be applied explictly, public is the default access modifier
of the abstract class
-Constrctor, destructor are allowed                              -Constrctor, destructor are not allowed                             

51)Can we apply private or protected access modifier to interface?


-No

52)Why access modifiers can not be applied to members of interface?


  - By default members of interface are public and members of the interface must be always exposed.

53)Why object can not be created for abstract class or interface?


    -Abstract classes are Partially unimplemented so that some of the members are not defined
    -Interface is fully unimplemented so that non of the member will have the implementation
    -If the object creation is made possible then we need to call the members with out implementation.     Thus object creation for abstract class and interface must be avoided

54)Can we declare member of interface as static?


  -No

55)Why multiple inheritance is not possible for classes?


  -Deriving a new class from two or more bases classes is called multiple inheritance
  -when the class is derived from too many base classes then there is a chance of duplicate memberes with full implementation
  -when that member is invoked w.r.t derived class object then there would be a ambigious situation.
  -to avoid this ambigious situationmultiple inheritance in classes is not allowed in c#.

56)What is private implementation for interface member?


   -while implementing the interface members if there are defined w.r.t interface name then it is called as private implimentation
   -In this implementation members must be private members of the class so that interface members can be invoked w.r.t interface variable name only but not w.r.t object of implemented class.
 -It is also called as explicit implimentation of interface

57)What is sealed class?


   -If a class is declared as sealed class then it can not be extended i.e inheritance is not possible for that class

58)What is Extension method and how to define it?


  -If a method is defined  to provide extra functionality to existing type with out disturbing its originallity then it is called as extension method.
   -it is introduced from C# 3.0
   -It must be static method
   -IT must be defined with in the static class
   -it must have the parameter of the type to be extended
   -parameter must be preceeded by this keyword

59)Can we Overload destructor?


-No

60)What is the use of Dispose()?


  -It is used to invoke the  GC dynamically.


For Part-1  click here
For Part-3  click here

Thanks for visiting this blog. How is the content?. Your comment is great gift to my work. Cheers.

No comments:

Post a Comment