We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Sunday, May 3, 2015

Interview questions and answers of OOP Concept in C#



1. What is the difference between Object-based programming and Object-oriented programming?

-if a language supports only encapsulation then it is called as object-based programming language ex: vb
-if a language supports encapsulation, inheritance, and polymorphism then it is called an object-oriented programming language.
ex:c#,java,c++

2. What are the main concepts of oops?

There are four main concepts of oops
a)Encapsulation
b)Inheritance
c)Polymorphism
d)Abstraction
e)method
f)object

3.what is encapsulation and its advantage?

-Grouping of related things together is called encapsulation.
-due encapsulation we can achieve portability.

4.what is Data hiding?

-Hiding unnecessary information from the user is called data hiding.
-due to data hiding, we can protect the behavior of a component.
-data hiding can be implemented by using access modifiers.

5.what is abstraction?

-Hiding complete implementation details from the user is called abstraction.
-Due to abstraction, we can make the user feel easy and comfortable while using component.
-It is hiding the details.

6.what is the difference between data hiding and abstraction?

-DataHiding is hiding unnecessary information from the user, so that we can protect the behavior of a component.
-Abstraction is hiding of complete implementation details, so that component usage becomes easy.

7.what is the difference between encapsulation and class?

-Encapsulation is an oops concept but class is a feature of language by which we can implement encapsulation.

8. How to implement encapsulation in C#?

-By using class, struct, interface, enum.

9.what are the access specifies?

There are four access modifiers
a)private
b)protected
c)Public
d)internal.
e)protected internal
d)private protected internal
we can combine protected and internal

10.what is the behavior of protected internal?

-protected internal is a combination of two access modifiers.
-within the same assembly, it will be like an internal, outside assembly it will be like a protected.so that we can make use of it in any class of the same assembly and only derived classes outside the assembly.

11.what is an object?

-it is an instance of the class.

12.what is min size of the object if there is no member in class?

-8bytes

13.what is the default access modifier for class?

-internal

14.what is the default access modifier for members in class?

-private

15.what is the base class for all classes in .net?

-System.Object.

16.what is the difference between class and structure?

                   Class                                                              struct

-It is reference type                                     -it is a value type
-All-access modifiers allowed                        -protected not allowed.
-All types of methods allowed                       -Virtual and abstract methods                                                                            not  allowed.
-Destructor is allowed                                 -destructor not allowed.
-All types of constructors allowed                 -default constructor not allowed.
-Inheritance possible                                   -inheritance not possible
-It can implement the interface                   -it also can implement the interface.

17. Is it possible to define method in enum type?

-no

18. How to initialize object?

-in two ways we can initialize an object.
a) By using object initializer.
b) By using Constructor.

19.what are accessor and mutator methods?

-a method that is designed to get value from variables of the class is called an accessor method.
-a method that is designed to modify the values of variables of the class is called as mutator method.

20.what is the difference between property and indexer?

-property is a member of class or struct which provides a flexible mechanism to read and write from and to the variable of class or struct.
-it can be static.
-it cannot be overloaded.
-The indexer is also a member of class or struct which is also providing a flexible mechanism to read and write from and to the variable of class or struct by using subscript and index.
-the indexer can not be static.
-always the name of indexer must be this, and it can be overloaded

21.is it possible to define property as static?

-yes

22.is it possible to define indexer as static?

-no

23.what is the use of base keyword?

-with the help of base keyword, we can access base class members from the derived class.
-always base keyword will refer to immediate base class members.
-we can call a base class constructor from the derived class constructor.

24.What is Constructor?

-it is a special method in the class which is invoked automatically when the class has been instantiated.
-it can be used to initialize instance variables of class to some meaningful initial values once the object has been created.

25.Why the name of the constructor and class name must be the same?

-to make the compiler to identify it easily.

26.Why return type is not allowed for constructor at the programmer level?

-the constructor should not be used for any other purpose, it must be used for only initialization.

27.What are the different types of constructors available?

-static constructor
-nonstatic constructor
a)default constructor b)parametric constructor.

28.Explain static constructor?

-A constructor can be defined as a static member.
-the static constructor should not have access modifier
-it must be parameterless.
-it can not be overloaded.
-it can be used to initialize static variables of class but not nonstatic variables.
-it is invoked one and only once when the class has been loaded into app domain by the class loader.

29.when the static constructor is invoked?

-it is invoked one and only once when the class has been loaded into the app domain by the class loader.

30.is it possible to overload static constructor?

-no

31.what is the need for a copy constructor?

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

32.what is destructor and when is it invoked?

-it is also a 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 the same.
-it must be preceded by ~ character.
-access modifiers can't be applied
-It must be parameterless

33.what is a disadvantage of destructor?

-the destructor in the class is represented by finalize( )
-when GC decides 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 the reachable queue.
- finalize() of the object is invoked which the intern invokes finalize() of system.Object
-finalize() of system.object invokes GC to deallocatememory so that it ill be an extra burden to the GC when the destructor has been defined for the class.

34.when the class is loaded into 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 Keywords.

36.what is namespace?

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

37.can we apply the access modifier to a namespace?

-No

38.Is it possible to declare instance variables in a namespace?

-No

39.what is alias name for the 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.
- to avoid the conflict we can assign a temporary name to the duplicate member which is called as an alias name for the namespace.

40.what is the difference between namespace and class?

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

41.what is the difference between out and ref parameters?

Out ref
-it is write-only variable 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 be initialized while passing it -it must be initialized while passing to the method.
to the method - changes are reflected
-Changes are reflected

42.what is the purpose of params keyword?

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

43.what is binding?

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

44 . How many types of bindings are available?

- There are 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 running the application then it is called dynamic binding.

45.what is Method overloading?

-defining number of methods with the 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 type of method can be Overloaded.
-No Keyword must be required for the method.

46.what is Method overriding?

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

47. What is the type of()

-it is an operator that is used to extract complete type information dynamically.
-it will return System.Type object.

48.what is polymorphism?

- Having Different forms to the same method is called Polymorphism.
-With the help of polymorphism, we can perform different actions with a same method invocation

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 

-It is a Partially unimplemented class 
-Complete Abstraction is not Possible 
-All Types of members are allowed 
-public is the default access modifier

of the abstract class
-The object can not be created 
-Access modifier can be applied to the members 


Interface
-Fully Unimplemented class
-Complete Abstraction is possible
-Only methods, Properties and indexes are allowed
-Object cant not be created

-Access modifiers can not be applied explicitly,
-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?

Ans: 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 aambigious situation.
-to avoid this ambigioussituation multiple 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 originality 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 preceded by this keyword

59.Can we Overload destructor?

Ans: no

60.what is the use of Dispose()

-It is used to invoke the GC dynamically.

61.what is the difference between String and StringBuilder classes?

- Both are used to manipulate and maintain the string
-each method of the string will return another string object
-each method of string builder will manipulate with in the same object with out returning another string object

62.what is the advantage of var keyword?

- it is introduced from C# 3.0
-It is used to declare the local variables
-var type of variable must be intialized during the declaration itself.
-Type of variable will be decided based on its intialization
-It can not be intialized with null, but it can contain the reference of object
-var type of variable can not be passed as a parameter to the method.

63.Can we assign null to var type of variable?

--No

64.What is the purpose of checked and unchecked blocks?

-checked block is used to provide a piece of code where there is a chance of raising OverFlowException.
-Unchecked block does raise OverFlowException.

65.what is the difference between the abstract method and the virtual method?

abstract method virtual method
-----------------------------------------------------------------------------
-Abstract Keyword must be used -virtual keyword must be used
-It should not have a definition in the base class -It must have the definition in the base class
-It must be overridden in the derived classes -It may or may not be in the derived classes
-It must be with in the abstract class -It can be within the abstract and non abstract classes

66. Can we define a virtual method as a private member?

-No

67.can we define an abstract method as a private member?

-No

68. Can we define an abstract method as static?

-No

69. Can we declare a private class in a namespace?

-No, members of the namespace must be either internal or public

70.what is the difference between new and override keywords?

- New is used to create the object dynamically
-Override key word is used to override either virtual or abstract methods

71. Can we Create an object with out defining class?

-Yes, we can create an object by using the new operator with some initialization.
-Based on the intialization appropriate anonymous type will be defined by the compiler.

72. What is the purpose of this?

-it is a predefined reference variable which contains the reference of a current object or active object.
-when the names of the parameters and instance variable names are same then
instance variables can be differentiated from the parameters by using this keyword.
-This can be used with instance methods only.

73.what is the difference between Array and ArrayList?

Array ArrayList
----------------------------------------------------------------------------------------------
-it is typed collection -it is an untyped collection
-fixed-size -size will be increased dynamically.
-boxing and unboxing not needed -the extra burden of boxing and unboxing

74. What is the difference between List and ArrayList?

List ArrayList
--------------------------------------------------------------------------------
-it is a generic collection -it is the nongeneric collection
-boxing and unboxing is not needed -Extra burden of boxing and unboxing
-the size will be increased dynamically -size will be increased dynamically

75.what is the difference between Hashtable and SortedList?

-both the collections are defined as Dictionaries wherein elements are stored in the form of (key, value) pair,
but in sorted list values are maintained according to keys in ascending order.

76.what is assembly?

-it is a language-independent, self-described portable software component.

77. Is IL language is OOP?

-no

78.what are different types of assemblies?

-there are three types of assemblies
a)private assembly
-an assembly without a strong name key is called a private assembly
-when the private assembly is used in the application, then a copy of it will be available as part of the application.
so that memory will be wasted when too many application is running at a time.
-if some changes are made in assembly then they have not reflected the application until its compilation.

b)public or shared assembly:-an assembly with strong name key and placed in GAC is called a shared assembly or public assembly.
-Advantages
-no memory wastage if even too many application using the same assembly is running.
-if some changes are made to assembly then those changes have automatically reflected the application without recompilation

c)satellite assembly
-it is private or public assembly with a resource file.
-it is used while creating an assembly for multi-linguistic purposes.

79. What is the digital signature of an assembly?

-it is a combination of the private key and hash algorithm value of assembly.
-the digital signature of an assembly will be checked while installing it into GAC.

80.what is a PE file?

-an assembly with win32 header is called as PE() file
-it is microprocessor independent.

81.what is ilasm.exe?

-it is a tool that is used to convert the assembly into the PE file.

82. What is ILDASM.exe?

-it is also a tool that is used to see the content of assembly in text format.

83. What are the advantages of generics?

-Boxing and unboxing burden can be reduced while working with collections.
-Code burden on developer can be reduced.

84.What is boxing and unboxing?

-Converting value type into reference type is called as boxing.
-During boxing typecasting will be done implicitly
-Converting reference type to value type is called as unboxing
-during unboxing, typecasting must be done explicitly

85. What are the disadvantages of boxing and unboxing?

-During boxing and unboxing, values must be copied from method stack to managed heap and vice-versa.
-During unboxing if typecasting is not done properly then it will raise an exception called InvalistCastException.

86.what is a delegate?

-it is a reference type which represents method.
-the delegate object can contain the reference of method
-with the help of the delegate object, we can invoke a method dynamically based on its reference.

87.what are different types of delegates?

there are two types of delegates
a)single cast delegate
-if a delegate object contains only one method reference then it is called a single cast delegate.
b)multicast delegate
-if a delegate object contains more than one method reference then it is called a multicast delegate.
-with the help of multicast delegate, we can invoke multiple methods sequentially with a single call.

88.what is a lamda expression?

-representing complete method definition with the help of simple expression is called a lambda expression

89. What are the different types of lambda expressions?

-there are two types of lambda expressions
a)predicate: A lambda expression which is designed to return either true or false is called predicate
b)projection: A lambda expression which is designed to return other than true or false is called projection.

90. What is the Annynomous method?

A method that is assumed by the compiler based on the definition of the delegate and definition of the method given
by the developer is called an anonymous method.

91.what is dll hell problem?

-in a windows environment, all application dll s are copied to system32 folder of windows directory so that there is a chance of overwriting one application dll by another application dll.
-if share dll s are used by multiple applications then due to uninstallation of one application another
application may be effected which is called as dll hell problem.

92.explain different parts of the assembly version?

Assembly version contains four parts
a)major:this part indicates the new namespace,class ,interface ,delegate insertion into assembly
b)minor: this part indicates the new methods, properties,,, insertion into assembly
c)Build: this part indicates the number of times bugs fixed in assembly
d)revision: this part indicates how many times assembly has been rebuilt irrespective of bugs reported or not

No comments: