Object oriented programming concepts
Tags: oops
Published: 2020-03-05 06:37:05

##Introduction##

OOPs is a programming paradigm . It contains objects and fields which holds the data and methods.In OOPs paradigm, each object can interact with each other. 

It is based on access modifiers. The object oriented paradigm is basically based on the classes and objects only. Objects are the instances of classes. We can create classes and objects in different ways. 

Many Programming languages are based on Object Oriented paradigm, which are : C++, PHP, C#, Java, Python, etc. 

**Some of the main features of Object-oriented Programming are mentioned below : **

Abstraction
Encapsulation
Inheritance
Polymorphism.

Almost every dynamic programming language is based on these principles. 

This list will help you in learning [OOPs interview questions and answers](https://techblogstation.com/interview/oops-interview-questions/) :

We have prepared this list to help you in technical interviews for programming languages like C, Java, Python etc. 

This list is divided into two sections (Basic and Advanced). So let’s get started : 

##Section 1 – Basic OOPs Interview Questions##

This part covers the basic OOPs Interview Questions and Answers : 

##Q1. What are the core concepts of OOP ?##

The core concepts of OOPs are mentioned below : 

Object
Abstraction
Encapsulation
Inheritance
Polymorphism

**Object** is a real world entity. Abstraction is the concept for hiding the complex implementation and shows only necessary information to users. 

Abstraction means incomplete. Encapsulation concept applies on Classes, It is the process where data and code is binded together. 

A class holds the fields and methods thus it holds data and logic into single unit. Polymorphism means many forms. 

It is the process of defining same name methods with different arguments. There are two types of polymorphism : runtime polymorphism and compile time polymorphism. 

##Q2. What is a Class in OOP ?##

In OOPs, a class a template or a blueprint. It is the representation of an Object. 

An object or an instance of a class will hold the same properties as of class. A Class in OOPs terminology can have different subclasses and super classes. 

An object is always specific to one class. However, a class can have multiple objects.Depending upon the class declaration, class behaves as a child or a parent class. 

We can extend any class can then the extending class will be the parent class.The subclass of any class will have all the properties of its parent class. However, the superclass cannot have the properties of the subclass. 

##Q3. What is a constructor in OOP ?##

A constructor is a special type of method. It is used for invoking the object creation and we can also initial the state of object with constructors.

**It has some rules such as :**

The name of constructor will also be same as class name. A constructor does not have any explicit return type. 

##Q4. What is the Destructor in OOP ?##

A Destructor in OOPs is opposite of Constructor. 

It is a method which is invoked when the object is destroyed or when object’s scope is about to end. 

It depends on the programming language whether this method will be called explicitly or implicitly. 


In C++ language, the destructor needs to be explicitly called. However, In Java OOPs It is implicitly handled by garbage collection mechanism. 

##Q5. What is an Abstract class in OOP ?##

An abstract class is the incomplete class which does not have the implementation of some of its methods.

It has abstract and non abstract methods. The abstract class cannot be instantiated. 

If we try to instantiate the abstract class, compilation error will occur.Any class which is created using the abstract class is called a derived classes. 

An abstract class does not have the implementation code in its base class. 

##Section 2 – Advanced OOPs Interview Questions##

##Q6. What is multiple inheritance in OOP?##

Multiple inheritance is the concept where one single class can inherit multiple classes. Java does not support multiple inheritance. 

However , C++ does support the multiple inheritance concept. It creates diamond problem, it is the situation of ambiguous behavior ths it is not supported by Java. 

Suppose, If we extend two classes and both these classes have same name method then the compiler will get confused which method to call. 

##Q7. What is static and dynamic binding in OOP ?##

**Static binding** is the binding happens at compile time. It is also known as early binding. Dynamic binding is the binding happens at run time.

It is also known as late binding. Method overloading is the example of static binding. Example of dynamic binding is method overriding.

The binding process for final, static and private methods is done at the compile time. However, the overriding is done at runtime.

If we bind the overloaded methods then it is called as static. However, the overridden method’s binding is called dynamic. 

##Q8. What is operator overloading in OOP ?##

Operator overloading is often known as ad-hoc polymorphism. It is the process where different operators will have different mechanism. 

It is based on the placement of operators and its arguments. Operator overloading is often not recommended as it redefines the semantics of the programming language.

Java does not have Operator overloading feature. 

##Q9. What is exception handling in OOP ?##

This is the one of the most asked OOPs Interview Question. Exception handling is the mechanism which is used in almost every object-oriented programming language.

It is the process of handling the exceptions of program during its execution. It helps in uninterrupted execution of a program in case of any exception arises.

The flow of execution is changed if the exception arised. Exception Handling has concepts such as try, catch and throw for C++, Java etc. 

try block consists of the code which needs to be executed and there is possibility of exception. 

catch block has the code which needs to be executed in case of exception arises. 

##Q10. What are the benefits of OOPS techniques ?##

Below are some of the main benefits of the OOPS : 

modularity
extensibility
simplicity
reusability
maintainability
modifiability etc.


**Thanks for Reading!!**