When preparing for an interview for a software engineering position, you should always keep in mind that besides knowing the certain technology you are interviewing for, you should be well-prepared with some basic Object-Oriented programming theory.
Object-Oriented programming principles are the fundamental building block of every modern programming language or concept. The most widely used programming languages are Object-Oriented, including Java, Python, C#, C++
etc. They all implement the basic OOP principles, so when working with an Object-Oriented language, you should possess strong knowledge of the OOP basic theoretical principles.
When interviewing, your tech interviewer will most probably ask you a couple of basic OOP questions, in order to verify that you have the necessary fundamental knowledge and that you understand the principles of OOP, no matter what experience, or knowledge in a certain tech stack you have.
In this article, we are going to ask and answer 15 of the most important OOP interview questions to prepare you for your next interview.
1. What is Object-Oriented Programming?
Object-Oriented Programming is a programming paradigm defined using objects instead of only functions and methods. The objects contain data, called attributes, and methods that provide the logic or supporting code for a given logic unit. Some of its main principles include inheritance, polymorphism, encapsulation, and abstraction.
2. What are some advantages of Object-Oriented Programming
- Problems of any level of complexity can be supported
- Highly complex problems can be handled
- It provides an efficient mechanism for code reuse using inheritance which reduces redundancy
- It provides a mechanism for hiding data
- It is based on a bottom-up approach
- It offers flexibility through polymorphism
- It improves the maintainability of the code
3. What are the main principles of OOPs?
Object-Oriented Programming has four main principles, and they are the following:
- Inheritance
- Encapsulation
- Polymorphism
- Data Abstraction

4. What is a class?
A class defines the definition of an object, and thus, it can be used to create objects at runtime. It provides the data structure, initial values for the attributes, and methods that provide the logic for the intended behavior of the object.
1class Test {
2 // member variables
3 // methods
4}
The class does not consume memory at runtime.
A class refers to a logical entity- for example, a vehicle
may be defined as a class.
5. What is an object?
An object refers to the runtime instance created from the class during program execution. Objects can refer to real-world entities that have attributes and methods (logic) to support the behavior. Objects consume memory space only after they are initialized.
1// Declaring and initializing an object
2let t = new Test();

6. What is a constructor?
A constructor is a method that is used for initializing the objects, from their classes. They are special types of methods that have the same name as the class, and they can be parameterless or initialize values for the attributes of the object.
There are three types of constructors:
– Default Constructor – Without parameters
– Parametric Constructor – Includes parameters to create a new instance of a class and also pass arguments simultaneously to provide different values to the distinct objects at the time of their creation
– Copy Constructor – Creates a new object as a copy of an existing object
xxxxxxxxxx
class Test {
constructor(id, name) {
this.id = id;
this.name = name;
}
// The 'constructor' acts as a default constructor when not sending parameter value
}
let ob1 = new Test();
let ob2 = new Test(123, "TestPerson");
console.log(ob1.id);
console.log(ob1.name);
console.log(ob2.id);
console.log(ob2.name);
Are you sure you're getting this? Is this statement true or false?
The classes' memory consumption depends on the number of attributes.
Press true if you believe the statement is correct, or false otherwise.
7. What are access modifiers?
Access modifiers specify the scope of accessibility of a data member, method, constructor or class. Depending on the language there can be various modifiers, but there are three main and shared betweem all of the OOP languages, that are fundamental.
Access Modifier | Definition |
---|---|
public | No restricted access, from same assembly (or package) or a referencing one |
private | Access limited to the containing type (class or struct) |
protected | Access limited to the containing class or derived classes |
8. Explain the concept of inheritance
Inheritance is one of the main features of object-oriented programming which allows classes to inherit properties and methods from other classes. This helps improve code reuse.
For example, we can have a base class called animal
, that may define the common properties shared by all animals. Then, we can define child classes such as: mammals
, reptiles
, etc. that will inherit the common attributes of all animals but will be able to define their own specific attributes and methods.

However, there are some limitations of the process of inheritance, for example, it requires more processing time for the programs as it has to navigate various classes during execution. Also, due to inheritance, the parent and child class are tightly coupled. When any changes are needed in the logic, it may require changes in both parent and child classes.
If the inheritance is not correctly implemented, it can lead to undesired results.
9. What are the various types of inheritance?
The various types of inheritance include:
- Single inheritance - A class inherits the properties of a single parent class.
1class A {
2 //parent class code
3}
4
5class B extends A {
6 //child class code
7}
- Multiple inheritances - An object or class can inherit features from more than one parent object or parent class. Not supported in all programming languages.
- Multi-level inheritance - One class has more than one parent class but at different levels of inheritance
1class A {
2 // parent class code
3}
4class B extends A {
5 // your code
6}
7class C extends B {
8 // your code
9}
- Hierarchical inheritance - One parent can have one or more child/sub/derived classes
1class A{
2 //parent class code
3}
4class B extends A {
5 //child class code
6}
7class C extends A {
8 //child class code
9}
- Hybrid inheritance - Combination of more than one type of inheritance in a single program
1 A
2 /
3 B C
4 /
5 D E
10. What is polymorphism?
Polymorphism is a significant feature of object-oriented programming that represents the ability for existence in multiple forms. A single interface
can be implemented in multiple ways by providing various definitions and implementations.
In Object-Oriented Programming languages, there are two types of polymorphism: 1. Static Binding (or Compile time) Polymorphism, e.g., Method Overloading
1function add(a, b){
2 return a+b;
3}
- Dynamic Binding (or Runtime) Polymorphism, e.g., Method overriding
xxxxxxxxxx
class Phone{
message(){
console.log("Message");
}
}
//Extending the Phone class
class iPhone extends Phone{
//Overriding message() of Phone class
sms(){
console.log("iPhone Message");
}
}
let mess = new iPhone();
mess.sms();
Are you sure you're getting this? Click the correct answer from the options.
Which of the following are inheritance types?
Click the option that best answers the question.
- Hybrid
- Multiple
- Hierarchical
- All of the above
11. What is method or operator overloading?
The method overloading is a feature of object-oriented programming in which multiple methods can have the same method name with different arguments. The call to the method is resolved based on the arguments.
Operator overloading means that depending on the arguments passed, the operators’ behavior can be changed. However, it works only for user-defined types.
12. What do you know about encapsulation?
Encapsulation is an important feature of object-oriented programming which allows the binding of the data and the logic together in a single entity. It also allows the hiding of data, so it is also known as a combination of data-hiding and abstraction.

- Declaring the variables of a class as private
- Providing public setter and getter methods to modify and view the variables' values
13. What is an abstraction?
Abstraction shows only the necessary details to the client of an object. This means that it shows only required details for an object, not the inner constructors of an object.
For example, if you turn on the TV, you do not need to know the inner mechanism needed to do that, so whatever is needed to turn it on will be shown using an abstract class.
You can achieve abstraction in two ways:
- Using Abstract Class Abstract Class is a class which is declared with an abstract keyword and cannot be instantiated. Few pointers to create an abstract class:
- It can contain abstract and non-abstract methods
- It can contain constructors and static methods as well
- It can contain final methods which force the subclass not to change the body of the method
You cannot create an instance of an abstract class since it lacks implementation logic in its methods. You first need to create a subclass that implements all the methods before an object can be initialized.
1class MyAbstractClass {
2 abstractMethod() {
3 throw new Error("This method is abstract and must be overridden");
4 }
5
6 display() {
7 console.log("method");
8 }
9}
- Using Interface An interface is a blueprint of a class that contains static constants and abstract methods. It represents the IS-A relation. You need to implement an interface to use its methods or constants.
xxxxxxxxxx
class Main {
constructor() {
const c1 = new Ford();
c1.start();
const c2 = new Toyota();
c2.start();
}
}
// Creating Car class
class Car {
start() {}
}
// creating classes that extends Car class
class Ford extends Car {
start() {
console.log("Ford Car");
}
}
class Toyota extends Car {
start() {
console.log("Toyota Car");
}
}
new Main();
Let's test your knowledge. Fill in the missing part by typing it in.
If we set the variables and attributes private
, and make public
methods for accessing them, we are implementing what OOP principle?
Write the missing line below.
13 What is the difference between data abstraction and encapsulation?
Data abstraction is the ability to hide unwanted information.
The encapsulation refers to the ability to hide the data as well as the method together.
14. What are the differences between interfaces and abstract classes?
An abstract class can support both abstract and non-abstract methods. However, the interface allows only abstract methods.
In the case of an abstract class, both final and non-final variables are supported, but the interface has variables that are defined as final by default.
The abstract class can have private, and public attributes, but interfaces have attributes as public by default.
15. What is a try-catch block?
A try-catch block is used for exception handling, and the statements that may cause a potential error are enclosed in a try block
. When an exception is thrown, it is caught by the catch block
, where the logic to handle an exception is placed.
The try-catch blocks are usually finished by using a finally block. A ‘finally’ block is used for executing essential statements such as to free the memory, close files, or database connections, even if an exception occurs. The finally
block always runs.
16. What is an exception?
An exception is a special event, which is raised during the execution of a program at runtime if there is an error during the execution. The reason for the exception is mainly due to a position in the program, where the user wants to do something for which the program is not specified, like undesirable input. The exceptions include a message with the details about the error that occurred.
Errors and exceptions are different, and an error means a problem that the program should not catch while the exception implies a condition that should be caught by the program.
In OOP there is a mechanism used for handling the exceptions raised during program execution, called exception handling. It allows for the graceful handling of undesirable results.
Are you sure you're getting this? Is this statement true or false?
Interfaces always have public attributes.
Press true if you believe the statement is correct, or false otherwise.
One Pager Cheat Sheet
- You should be prepared with basic Object-Oriented programming theory when interviewing for a software engineering position.
- Object-Oriented Programming (OOP) is a programming paradigm based on objects, which contain attributes and methods, with four main principles of
inheritance
,encapsulation
,polymorphism
, anddata abstraction
, that provide advantages such as code reuse, flexibility, and improved maintainability. - Only when an
object
is created does memory consumption occur, not based on the number of attributes of the class since classes are merely a logical entity. - In object-oriented programming,
polymorphism
is the ability of an object or a class to exist in multiple forms, and is realized using two types of binding, static and dynamic. - All of the listed
inheritance types
are fundamental features of Object-Oriented Programming. - Encapsulation, abstraction and method/operator overloading are important features of object-oriented programming that allow the binding of data and logic, hiding data and creating multiple methods with the same name respectively.
- Encapsulation is a key feature of Object-Oriented Programming that supports data-hiding and abstraction by making attributes
private
and usingpublic setter and getter methods
to access and modify them. - Exception handling using
try-catch blocks
andfinally block
allow for the graceful handling of errors and exceptions to take place during the execution of a program. - Interfaces have
public
visibility by default, so that any implementation class must adhere to thepublic
exposed methods and attributes when implementing the interface.