Ad Code

Part - 1 : Oops Interview Question's & Answer

1. What is mean by Class?

Class is a structure that describes the state (property) and behavior (methods) of the object. It is a template or blueprint to create objects of the class. Class represents the noun and it can be used as type in programming language. E.g Car, Person etc

2. What is mean by Objects?

Object is an executable copy of a class. State and behavior of the objects are defined by class definition. We can create multiple objects for single class. It is also called as instance of the class. When an object is created from the class, memory will be allocated in RAM. e.g CarMaruthi, Alto, Zen etc. Person- Ram, Sam, John etc

3. What is mean by Struture?

Structure is a light-weight class used to create user-defined types containing only public fields. Structure can't have implementation inheritance, but it can have interface inheritance. We cannot modify the default constructors as like a class. Structure is a value type holds their value in memory when they are declared.

4. What is difference between Class and Object?

Classes are the template or blueprint its state of how objects should be and behave, where as Object is an actual real term object. E.g CAR define state like it should have four wheel and body structure with moving, accelerating and break functionality. Maruthi, Alto or Zen is the real object which has different kind of state from one another.

5. What is difference between Class and Structure?

  1. Class is Reference type(Reference types hold a reference to an object in memory) -Structure is a Value type(Value types hold their value in memory when they are declared)
  2. User can modify default constructor and destructor of class- structure can't modify default constructor
  3. Class supports inheritance - Structure will not support inheritance
  4. Classes must be instantiated using the new operator - Structure can be instantiated without using the new operator

6. Which case we have to use Class and Structure?

Structure can be used for things that we no need for identity. Class can be used when we need the identity for an object.

7. What is the advantage of Structure over Class?

Since Stucture is a value type and if we use at the proper location, it will improve the performance.

8. What are different access modifiers in .Net?

  1. Private - The type or member can only be accessed by code in the same class or struct.
  2. Protected - The type or member can only be accessed by code in the same class or struct, or in a derived class.
  3. Internal - The type or member can be accessed by any code in the same assembly, but not from another assembly.
  4. Procted Internal - The type or member can be accessed by any code in the same assembly, or by any derived class in another assembly.
  5. Public - The type or member can be accessed by any other code in the same assembly oranother assembly that references it.
Note: In VB.Net 'Internal' is called as 'Friend'

9. What are advantages of using private constructor, method, property?

Due to security reason, methods and properties are not exposed outside the class using Private access modifier. For implementing Singleton pattern we go for Private Constructor, so we will not able to create instance. Separate method is used to create and return the instance.

10. What is mean by Partial class?

It is new features in .Net 2.0; partial classes mean that class definition can be split into multiple physical files. Logically, partial classes do not make any difference to the compiler. The compiler intelligently combines the definitions together into a single class at compile-time. Example for Partial Class
partial class Employee
    string m_Name;
   public String Name
      get { return m_Name; }
      set { m_Name = value; }

partial class Employee
   int m_Age;
  public int Age
    get { return m_Age; }
    set { m_Age = value; }

public class ExampleofPartical
   public void Method1()
      Employee objClass1 = new Employee();
      objClass1.Age = 12;

Post a comment