P2Pprogrammer 2 programmer


Home > Interview Question and Answer > C# and VB.Net > .NET Object-Oriented Programming (OOPs)

.NET Object Oriented Programming (OOPs) Interview Question and Answer


Interview questions and answers for .NET Object-Oriented Programming (OOPs). OOPS, Enums, Properties, Method, event, Delegate, Class, Object, Inheritance, Abstract Class, Interface, Overloading, Polymorphism, arrays and collection, encapsulation, shadowing and overriding, must inherit, dispose, constructor, destructor, dispose, access modifier.

Advanced .NET Framework OOPs Interview Question and Answers



Interview questions and answers for .NET .NET Object-Oriented Programming (OOPs)


1. Explain when a type conversion will undergo an implicit cast and when you must perform an explicit cast. What are the dangers associated with explicit casts?

Types can be implicitly converted when the conversion can always take place without any potential loss of data. When a potential loss of data is possible, an explicit cast is required. If an explicit cast is improperly performed, a loss of data precision can result, or an exception can be thrown.

2. Explain why you might use enums and constants instead of their associated literal values.

Enums and constants make code easier to read and maintain by substituting human-legible tokens for frequently used constant values.

3. Briefly summarize the similarities and differences between arrays and collections.

Arrays and collections allow you to manage groups of objects. You can access a particular object by index in both arrays and collections, and you can use For Each…Next (foreach) syntax to iterate through the members of arrays and most collections. Arrays are fixed in length, and members must be initialized before use. Members of collections must be declared and initialized outside of the collection, and then added to the collection. Collections provided in the System.Collections namespace can grow or shrink dynamically, and items can be added or removed at run time.

4. Explain how properties differ from fields. Why would you expose public data through properties instead of fields?

Properties allow validation code to execute when values are accessed or changed. This allows you to impose some measure of control over when and how values are read or changed. Fields cannot perform validation when being read or set.

5. Explain what a delegate is and how one works.

A delegate acts like a strongly typed function pointer. Delegates can invoke the methods that they reference without making explicit calls to those methods.

6. Briefly explain how to convert a string representation of a number to a numeric type, such as an Integer or a Double.

All numeric data types have a Parse method that accepts a string parameter and returns the value represented by that string cast to the appropriate data type. You can use the Parse method of each data type to convert strings to that type.

7. What are the two kinds of multidimensional arrays? Briefly describe each.

Multidimensional arrays can be either rectangular arrays or jagged arrays. A rectangular array can be thought of as a table, where each row has the same number of columns. Rectangular arrays with more than two dimensions continue this concept, where each member of each dimension has the same number of members of each other dimension. Jagged arrays can be thought of as an array of arrays. A two-dimensional jagged array is like a table where each row might have a different number of columns.

8. Briefly explain encapsulation and why it is important in object-oriented programming.

Encapsulation is the principle that all of the data and functionality required by an object be contained by that object. This allows objects to exist as independent, interchangeable units of functionality without maintaining dependencies on other units of code.

9. What is method overloading, and when is it useful?

Method overloading allows you to create several methods with the same name but different signatures. Overloading is useful when you want to provide the same or similar functionality to different sets of parameters.

10. You need to create several unrelated classes that each exposes a common set of methods. Briefly outline a strategy that will allow these classes to polymorphically expose that functionality to other classes.

Factor the common set of methods into an interface, and then implement that interface in each class. Each class can then be implicitly cast to that interface and can polymorphically interact with other classes.

11. What is Interface?

An interface is a contract. Any object that implements a given interface guarantees to provide an implementation of the members defined in that interface. If an object requires interaction with a specific interface, any object that implements that interface can supply the requisite interaction.

12. Describe an abstract class and explain when one might be useful.

An abstract class is a class that cannot be instantiated but must be inherited. It can contain both implemented methods and abstract methods, which must be implemented in an inheriting class. Thus, it can define common functionality for some methods, a common interface for other methods, and leave more detailed implementation up to the inheriting class.

13. What is abstract members?

Abstract members A member of a base class that cannot be invoked, but instead provides a template for members of a derived class. In Visual Basic .NET, abstract members are declared using the MustOverride keyword. In Visual C#, abstract members are declared using the abstract keyword.

14. What is base and derived class?

base class, A class that provides properties and methods as a foundation for a derived class. In objected-oriented programming, one class can be based on another through inheritance. Using this technique, the base class provides characteristics (such as properties and methods) to a derived class. The derived class can reuse, modify, or add to the members of the base class

derived class, A class that is based on another class (called a base class) through inheritance. A derived class inherits the members of its base class and can override or shadow those members.

15. What is encapsulation ?

Encapsulation In component programming, separating the implementation of a component from the interface. Only the public interface of a component is made accessible to the rest of the application. Component data should never be accessible to outside callers.

16. What is namespace?

Namespace A logical organization of types that perform related functions.

17. What is polymorphism ?

Polymorphism The ability of classes to provide different implementations of the same public interface. Thus, two classes that exhibit polymorphism might contain different implementations, but because the interfaces are identical, they can be treated the same in code.

More C# and VB.Net Interview Question and Answers

  1. .NET Framework interview questions and answers
  2. VB.NET and C# User Interface interview questions and answers
  3. .NET Object-Oriented Programming (OOPs) interview questions and answers
  4. ADO.NET interview questions and answers
  5. Advanced .NET Framework Topics interview questions and answers
  6. Windows Service, COM+ and XML Web Services interview questions and answers
  7. .NET Assemblies, Configuration, and Security interview questions and answers
  8. VB.NET and C# setup and deployment interview questions and answers
  9. VB.NET and C# general interview questions and answers


Home > Interview Question and Answer > C# and VB.Net > .NET Framework