OOPS Interview Questions and Answers

1. Could you define what is Object Oriented Programming (OOP)?

Object-oriented programming (OOP) is a programming paradigm in which programs are considered as a collection of objects and these objects are used to design and build applications. An object is nothing but a model of the concepts, processes or things in the real world that are meaningful to the application. OOP provides many concepts like inheritance, abstraction, data binding, polymorphism etc. Simula is considered as the first object-oriented programming language. Significant object-oriented languages are C++, C#, Java, PHP, Python, Ruby, Delphi, Perl, Objective-C, Swift, Common Lisp and Smalltalk.

2. Please define an object with its use in OOP with its desirable qualities.

An object is a block of memory that has been allocated and configured in a class. There can be many objects in a class and can be stored in either a named variable or in an array or collection. We can say that an object is a self-contained component consists of properties and methods required to make a particular type of data useful. Objects are used to interact with one another to build applications. Perfect use of objects makes it easier to develop, upgrade and maintain the application. For example, in a inventory management application, we would have a purchase object, a order object and a sale object. Its desirable qualities are Modularity, Information Hiding and Code Reusability.

3. Enumerate the characteristics of Object Oriented Programming (OOP).

Main characteristics of object oriented programming (OOP) are-

  • Object - It is a real word entity such as book, chair, table etc.
  • Class - It is a collection of different objects
  • Abstraction - To hide all the data except the relevant data regarding an object improve efficiency
  • Encapsulation - To wrap code and data together in a single unit
  • Inheritance - To reuse and extend existing classes
  • Polymorphism - To perform single task in multiple ways
  • Dynamic Binding - When linking of a function with an object is done during runtime. It is also called late binding
  • Message Passing - To send and receive the information among objects with the help of function parameters

4. Please state the advantages of using Object Oriented Programming (OOP).

The advantages of using Object Oriented Programming (OOP) are-

  1. It uses real world object and generic programming approach
  2. Objects can be reused in other program
  3. It is component oriented
  4. It provides a simple and clear modular structure for programs
  5. Important properties like classes, methods, instance, message passing and dynamic binding are provided
  6. It has incorporated different concepts like abstraction, encapsulation, inheritance and polymorphism
  7. New features can easily be added without disturbing the existing one
  8. It is easy to maintain and make required changes in existing applications as new objects can be created by implementing small changes in existing ones
  9. Program modularity is enhanced in OOP as each object is independent in it
  10. It provides a good framework for code libraries

5. Please define a Class.

A class is a set of instructions to build a specific type of object. Class contains the data members and member functions. Data need to be well defined in a class. It is to be noted that following the concept of single responsibility, each class should be designed to perform only one task. Many classes should be used to build an entire application.
The keyword class in C# shows that we are going to define a new class. A class is stored in a heap. Classes can be inherited which means a class can create a subclass.

6. What is an Abstract Class?

Abstract class is a class that cannot be instantiated into objects, it exists extensively for the purpose of inheritance and it must be inherited. It may contain one or more abstract methods. Abstract method is a method that is declared but does not contain any implementation.

7. Please tell me when would you use Abstract Classes?

Abstract classes should be used:
While designing large functional units
For the objects that are closely related
If we want to build multiple versions of our component
While providing common functionality among all implementations of the component

8. Please explain Public, Private and Protected Access Modifiers.

Public Access Modifier
It states that there are no restrictions on accessing public members of a class.
Private Access Modifier
It states that the scope of private members of the class will be limited to only that particular class. We cannot explicitly declare a class as Private but if we do not specify any access modifier to the class, it is assumed as Private.
Protected Access Modifier
It states that protected members of the class are accessible from within the class in which they are declared and from any class which is derived from the class that declares protected members.

9. Would you tell what are the default access modifiers in C#?

  • Class- Default access modifier is Private
  • Struct - Default access modifier is Internal
  • Method- Default access modifier is Private
  • Field- Default access modifier is Private
  • Property- Default access modifier is Private
  • Enum - Default access modifier is Private

10. Could you differentiate between abstraction and encapsulation?

It is used to hide all the data except the relevant data regarding an object improve efficiency
It is implementation oriented
Its focus is on the interface means the outer look of the object
It is used to wrap code and data together in a single unit
It is design oriented.
It does not allow other objects or methods to look into the properties and behaviour of any object