Thursday 24 November 2011

Dotnet OOPS interview questions



8. What’s the difference between an interface and abstract class?
Answer :

In an interface class, all methods are abstract - there is no implementation. In an abstract class some methods can be concrete. In an interface class, no accessibility modifiers are allowed. An abstract class may have accessibility modifiers. 

9. How is method overriding different from method overloading?
Answer :
When overriding a method, you change the behavior of the method for the derived class. Overloading a method simply involves having another method with the same name within the class. 
10. If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?
Answer :

Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class. 

11. What are the different ways a method can be overloaded?
Answer :

Different parameter data types, different number of parameters, different order of parameters. 


12. Can you prevent your class from being inherited by another class?
Answer :
Yes. The keyword “sealed” will prevent the class from being inherited. 

13. What’s the C# syntax to catch any possible exception?
Answer :
A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {} 

14. What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
Answer :
The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array. The CopyTo() method copies the elements into another existing array. Both perform a shallow copy. A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array. A deep copy (which neither of these methods performs) would create a new instance of each element’s object, resulting in a different, yet identacle object. 


15. What’s the advantage of using System.Text.StringBuilder over System.String?
Answer :
StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created. 

16. What’s the difference between System.String and System.Text.StringBuilder classes?
Answer :
System.String is immutable. System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed. 

17. What does the term immutable mean?

Answer :
The data value may not be changed. Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory. 

No comments:

Post a Comment

Please Give Your Valuable Comments on this Topic