OOPS FAQ's
Q: What is the difference between object based programming and object oriented programming?
Ans:
- If the programming methodology supports encapsulation,Inheritance and polymorphiam then, it is called object oriented programming language, it supports code extendability.
- If the programming methodology supports only encapsulation then, it is called object based programming language, it supports code extendability.
Q: What are the fundamental concepts of oops?
Ans:
- Encapsuplation
- Inheritance
- Polymorphism
Q: What is encapsulation and its advantage?
Ans: Grouping related thing together is called Encapsulation, we can acheive Portabily.
Q: How to implement the encapsulation in c#?
Ans: By using class,struct,properties,interface etc.
Q: What is DataHiding ?
Ans: Hiding unnecessary details from the user.
Q: What is the Advantage of DataHiding ?
Ans: Due to DataHiding behavior of the product can be protected, so that developers logic can be secured.
Q: What is Abstraction ?
Ans: Hiding complete implementation details from the user is called abstraction.
Due to abstraction user will feel comfortable while working with the product.
Q: Difference between DataHiding and Abstraction ?
Ans:
- DataHiding: Hiding unnecessary data from the user, programmer is benifited.
- Abstraction: Hiding complete implementation details from the user, user is benifited.
Q: What is Class ?
Ans: Class is a model or template regarding the thing.
Q: What is an Object ?
Ans: An instance of the class.
Q: What is the difference between Encapsulation and Class ?
Ans:
- Encapsulation: Is a objcet oriented programming concept.
- Class: it is a feature of the language by which we can implement encapsulation.
Q: What is the default access modifier for the class?
Ans: Internal
Q: What is the default access modifier for the members of the class?
Ans: Private
Q: What is the default access modifier for the members of the struct?
Ans: Private
Q: Difference between Class and Struct ?
Ans:
Class | Struct |
---|---|
1. Class is Object type | 1. Struct is Value type |
2. All accessmodifiers are allowed | 2. Protected is not supported |
3. Inheritance is possible | 3. Not possible |
4. Supports all types of constructors | 4. Default Constructor is not supported |
5. Distructor allowed | 5. Not allowed |
6. method overriding possible | 6. Not possible |
Q: What is Accessor Method and Mutator method ?
Ans:
- Accessor Method: Any of the method is defined to access the value from the instance variable.
- Mutator Method: Any of the method is defined to modify the value from the instance variable.
Q: What is the use of base keyword ?
Ans: To access the base class members in the derived class we can use base keyword. (or) To invoke the base class constructor from the derived calss constructor.
Q: What is the difference between property and indexer ?
Ans:
- If we use property we can get and modify the values from the instance variables .
- By using indexer we can access the object by applying subscript with index position.
Q: What is Constructor ?
Ans: Constructor is a special method in the class, which is used to initialize the instance variables to some meaning full initial values, when the class is instantiated.
Q: Why the name of Constructor and class is same ?
Ans: For easy identification purpose of the compiler.
Q: Can we overload distructor() ?
Ans: No, because it is parameter less.
Q: What is namespace ?
Ans: NameSpace is a logical container. Where in we can find classes, enumerations, interfaces delegates.
Q: What is the purpose of namespace?
Ans: To avoid the name collisions.
Q: What is the difference between namespace and class ?
Ans:
- Namespace is used to avoid the name collisions
- Class is used to implement encapsulation.
Q: What is the alias name for namespaces and when it is required?
Ans: When ever there is a conflict among the members in the included namespaces, then we can avoid it by providing alias nameto the member where there is a conflict.
Q: What is the purpose of params keyword ?
Ans: Params keyword is used to specify the array of parameters to the method.
Q: What is the difference between out and ref parameters ?
Ans:
- Out parameters are write only parameters in side the method.
- Ref parameters are read - write parameters in side the method.
Q: What is Binding ?
Ans: Replacing method invokation with its appropriate base reference is called Binding.
Q: What is static Binding ?
Ans: If the binding process is carried out at the time of compilation is called Static bonding.
Q: What is Dynamic binding ?
Ans: If the binding process is carried out at the run time is called Dynamic bonding.
Q: What are the difference between Method overloding and overriding ?
Ans:
Overloding | Overriding |
---|---|
1. Nothing but no.of methods defined with the same name by showing the difference in signature part | 1. Nothing but no.of methods defined with same name and same signature |
2. Possible with in the same class and derived class | 2. Possible in the derived class by the override keyword |
3. Possible for static, non-static methods | 3. Possible for only abstract and virtual methods |
Q: What is polymorphism ?
Ans: Performing different actions by invoking same invocation.
Q: What is the diff between abstract calss and interface ?
Ans:
Abstract class | Interface |
1. partially unimplemented | 1. Fully unimplipmented |
2. Complete abstraction is not possible | 2. Complete abstraction is possble |
3. All the types of members are allowed | 3. Onlymethods,properties,indexers and events are allowed |
Q: What is sealed class ?
Ans: If a class is declared as sealed calss, then it can not be inherited ex: Thread class.
Q: What is extension method?
Ans:
- From c# 3.0 we can find this.
- We can extend the functionality of existing data type by defining extension method.
- Always extension methos must be declared as static and defined in static class.
Q: What is the use of Dispose Method()?
Ans: It is used to Invoke the Garbage collector dynamically.
Q: What is the difference between string and stringBuilder?
Ans:
- String: String class objects will return another instance of the string for each operation.
- StringBuilder: Manipulation can be done with is the object itself.
Q: What is the difference between Abstract method and Virtual method ?
Ans:
Abstract Method | Virtual Method |
1. Must be inside abstract class | 1. It can be declared any where |
2. Must be overrided in its derived class | 2. It may or may not be overrided in its derived class |
3. Should not have the body in base class | 3. Must have the body in base class |