1. OOP Most asked interview
questions
On this slideshare we will be sharing Q &
A which will dig through some quick
basics on programming - OOP based
interview question and answers.
2. 1. What is OOP?
OOP Stands for Object Oriented Programming.
It deals with organizing a programming language model
around an object rather dealing with Actions and data
rather than logic.
Instead of procedural programming which is based on a
list of actions OOP is created to be modelled around
objects that interact with one another.
2. What is an Object in OOP?
Every Entity is considered as an object for which its
characteristics can be described by using features of OOP
concepts.
An Object can be defined as an Instance of a Class and
are basic run time entities.
3. 3. What is a Class?
A Class is at the core of Object Oriented
Programming
A Class can be said to be a Blueprint of an
object that contains functions to perform
action and variable to store data.
A class contains behaviour and Data in Entity.
A class can inherit behaviour and data
members from other classes.
4. 4. Explain Encapsulation in OOP?
Data Encapsulation is the Concept of hiding all the
implementation details of a class from the End-user by
binding data and code into a single unit.
In Encapsulation we define fields as Private as opposed
to declaring it as Public.
5. What is Polymorphism?
The word Polymorphism translates to having many
forms.Polymorphism can be expressed as ‘One
Interface, Multiple functions’ Polymorphism lets us
invoke methods of derived class through base class
reference during runtime.
5. 6. Explain Constructors?
A Constructor is a Special Method of a Class in a
program which gets invoked when the instance of a
class is created.
A Constructor must have the same name as the class
and it gets initialized whenever
The class gets initialized whenever we access that class.
A Constructor does not have a return type.
It can also be overloaded and it can be used to initialize
variables.
There are two types of Constructors:
Implicit and Explicit Constructors where implicit
constructors are internally created in .Net Framework
while we can declare explicit constructors as we wish.
6. 7. Explain Destructors?
A Destructor cannot be manually invoked in C#
It is automatically invoked when an object is to be
destroyed.
Name of the Destructor is the same as the Class
along with being prefixed with a tilde (~).
Destructor is used to clear dynamically allocated
memory and free the resources to allocate to
other process.
Destructors do not have a return type in C#.
Destructors are public by default and cannot be
overloaded.
7. 8. Explain Abstraction in OOP?
Abstraction is the Process of only displaying
relevant information without displaying the
background details.
Abstract Class: Incomplete class /Partial Class
Abstract Method: Incomplete function An
Abstract class can contain Abstract as well as
non-abstract methods. Abstract class must
always be public and must be declared with
the abstract keyword.
An Abstract class cannot be directly
instantiated.
8. 9. What is Interface?
An Interface can be defined as a Template and it
can contain only the Signature of the class in C#.
An Interface cannot contain any implementation.
Multiple interface inheritance along with a single
base class is possible.
When an Interface is declared public then its
function do not need to be declared with a public
keyword.
Base class must always be inherited prior to
interface.
9. 10. What is function overloading?
Function Overloading or Method Overloading
allows us to have two methods with same name
but different signature.
Overloading occurs at Compile time and can be
called as compile time polymorphism.
Method overloading can be used in the same
class or a child class in C#.
Method overloading can be used in C# by doing
the following:
Changing the number of parameters in the
method, changing the order of the parameters in
the method and using datatypes which are
different from each other.
10. 11. What is Method Overriding?
Method Overriding allows us to have two
methods with same name and same Signature.
Method Overriding occurs at Compile time and
can be called as compile time polymorphism.
Method overriding is only possible in child class
not inside the same class from where the method
is declared.
Method overriding can be done in C# by creating
a method in a derived class with same
parameters, same name and same return type as
in base class.
11. 12. What are Access Modifiers?
An access specifier defines the visibility and
scope of a class member in C#.
C# has Four Access Modifiers:
• Protected
• Internal
• Public
•Private
12. 13. What are the various types of
Constructors?
There are Five types of Constructors in C#:
• Default Constructor
• Parameterized Constructor
• Copy Constructor
• Static Constructor
•Private Constructor
13. 14. Explain Exception Handling?
In C# Exception handling features help us deal
with any unexpected or exceptional situations
which occur when a program is in run time.
Exception handling in C# uses the try
(Keyword), catch (Keyword), and finally
(Keyword) keywords to try actions which may
not succeed and to handle failures when you
decide that it is necessary to do so final
keyword executes regardless if an error occurs
or not.
14. 15. Explain the Difference between Abstraction
and Encapsulation?
Encapsulation involves wrapping and hiding
properties and methods. To protect the data
from the end user we use encapsulates which
hides the code and data into a single unit.
In C# class can be used as the best example of
encapsulation. In Abstraction we only show
the necessary details to the intended user.
15. 16. Explain Delegates?
C# act in a similar way as to that of C and C++
Pointers. A delegate is a reference type
variable that contains the reference to a
function and the reference can be changed at
runtime.
Delegates are usually used for call-back
methods and implementing events.
In C# all delegates are implicitly derived from
the inbuilt System.Delegate class.
16. 17. What are Events?
Events are Special members of the class that
invokes them. When an Action occurs a class
can raise an event, which have a message that
contain information’s about the event (event
arguments) and send them out to the rest of
the application, other parts of the application
can respond to the event by executing
methods called event handlers.
Event handler is a method in C# that has the
same signature as the event and this method is
executed when the event occurs.
17. 18. What are Nested Classes?
Nested Class is creating a class in another class
in C#. Nested Classes are instantiated
separately to its parent class and are not
instantiated automatically by its parent.
If a nested class is declared private it can only
be accessed by its parent class or other nested
class along with it.
18. 19. Explain Generics in OOP?
Generics in C# allows us to specify the
datatypes of a program which maybe used
inside a class or a method when the variable is
used in the program. Hence Generics allows
us write a Class or Method that can work with
any datatype in C#.
It allows us to implement core OOP features
such as Code reuse, Type Safety and
performance.
19. 20. Explain Inheritance?
Inheritance is one of the most important
concept of OOP in C#.
The main purpose of Inheritance is Code
Reusability and avoiding Code Duplication.
Instead of creating new Data Members and
Member Function for new class which already
exist we can just inherit it from existing class
that already contains those members.
20. 21. What is the default access specifier in a class
definition?
Private is the default access specifier in class
definition in C#.
22. What are the Types of Inheritance?
The different types of Inheritance in C# are as
follows:
• Single Inheritance: can only be inherited into one
child class.
• Hierarchical Inheritance: base class can be
inherited into multiple child classes
• Multilevel Inheritance: Contains a class derived
from a another child class.
Multiple inheritance is not supported in C#.
21. 23. What are Sealed Classes?
Inheritance can be disabled by using the
sealed keyword on a class or a method.
We cannot derive other classes from it when
use on a base class.
Derived classes can’t override the method
when used on a Method.
22. 24. Explain Static Classes and Members?
A Static class is the same as a non-static class
apart from the difference that a static class
cannot be instantiated or we use a new
keyword to create a variable of class type.
We can access the members of the static class
by using the class name.
Static members can be called even when no
instance of a class has been created in C#
Static members and properties cannot access
the non-static events and fields in their
containing type.
23. 25. What is Virtual Methods?
Virtual methods are methods which are
compulsorily declared with the virtual keyword.
The virtual keyword signifies that this method can
be overridden by a child class using the override
keyword.
26. What are the Types of the Polymorphism?
There two types of polymorphism :
• Static Polymorphism: Object is linked with
Method in Compile time.
• Dynamic Polymorphism: Object is linked to
Method in Runtime.
24. 27. What are the Advantages of OOP?
Advantages of OOP programming are Code
Reusability via Inheritance, Data Security via
encapsulation, Simple User interface via Abstraction
and structured class approach with Objects which
allows to maintain code with easy detection of
errors.
25. 28. Explain Difference between an Abstract class
and Interface?
In C# a Class can extend only one abstract
class while it can implement several
interfaces.
Interface can only have public members while
abstract class can be private and protected.
Interface can extend another Interface only
while any class can extend an abstract class
Interfaces cannot contain body of any of its
method or data members as opposed to an
abstract class which can implement methods.
26. 29. Explain Multicast Delegate?
A Multicast delegate is a variable which has
reference to more than one function.
All the functions to which the multicast
delegate point to are invoked when the
Multicast delegate is invoked.
There are two ways to create multicast
delegate are as follows:
• + or += to Subscribe a method with the
delegate
• - or -= to Unsubscribe a method with the
delegate