0% found this document useful (0 votes)
0 views

4 Object Oriented Programming Interview Questions

The document outlines a series of sample technical interview questions related to Object Oriented Programming (OOP) as part of the Computer Science and Engineering curriculum. It covers fundamental concepts such as OOP definitions, advantages, major languages, and key features like encapsulation, inheritance, polymorphism, and abstraction. Additionally, it discusses various programming paradigms, types of constructors, and differences between classes and structures.

Uploaded by

gyeastyour
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

4 Object Oriented Programming Interview Questions

The document outlines a series of sample technical interview questions related to Object Oriented Programming (OOP) as part of the Computer Science and Engineering curriculum. It covers fundamental concepts such as OOP definitions, advantages, major languages, and key features like encapsulation, inheritance, polymorphism, and abstraction. Additionally, it discusses various programming paradigms, types of constructors, and differences between classes and structures.

Uploaded by

gyeastyour
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Department of Computer Science and Engineering (Accredited by National Board of Accreditation)

Sample Technical Interview Questions


Department : Computer Science and Engineering
Name of Faculty: Dr. Piyush Choudhary
Subject: Object Oriented Programming and Methodology

1. What is meant by the term Object Oriented Programming?


(OOP) is a programming paradigm where the design is centered around objects. These objects are
instances of classes and consist of data (attributes) and behaviors (methods). OOP models real-world
entities, making code more intuitive and reusable.
2. What is the need for Object Oriented Programming?
OOP enhances code readability, maintainability, and scalability. It simplifies the development of large-
scale systems by promoting modularity, abstraction, and reusability. With OOP, developers can design
software that is easier to understand and extend, even without detailed knowledge of the underlying
implementation. Even very big software can be easily written and managed easily using Object Oriented
Programming.
3. What are some major Object Oriented Programming languages?
The programming languages that use and follow the Object-Oriented Programming paradigm or Object
Oriented Programming, are known as Object-Oriented Programming languages. Some of the major
Object-Oriented Programming languages include:
Java
C++
Javascript
Python
PHP
And many more.

4. What are some other programming paradigms other than Object Oriented Programming?
Programming paradigms refers to the method of classification of programming languages based on their
features. There are mainly two types of Programming Paradigms:
1. Imperative Programming Paradigm
2. Declarative Programming Paradigm
Now, these paradigms can be further classified as:

1|Page
Campus: Prestige Vihar, Scheme No 74-C , Sector-D, Vijay Nagar Indore- 452010 M.P.
Phone : 0731-4013333, 4013334 Fax : 0731-4013329 website : www.piemr.edu.in
Department of Computer Science and Engineering (Accredited by National Board of Accreditation)

1. Imperative Programming Paradigm: Imperative programming focuses on HOW to


execute program logic and defines control flow as statements that change a program state. This can be
further classified as:
a) Procedural Programming Paradigm: Procedural programming specifies the steps a
program must take to reach the desired state, usually read in order from top to bottom.
b) Object-Oriented Programming: Object-oriented programming (OOP) organizes programs
as objects, that contain some data and have some behavior.
c) Parallel Programming: Parallel programming paradigm breaks a task into subtasks and
focuses on executing them simultaneously at the same time.
2. Declarative Programming Paradigm: Declarative programming focuses on WHAT to
execute and defines program logic, but not a detailed control flow. Declarative paradigm can be further
classified into:
a) Logical Programming Paradigm: Logical programming paradigm is based on formal logic,
which refers to a set of sentences expressing facts and rules about how to solve a problem
b) Functional Programming Paradigm: Functional programming is a programming
paradigm where programs are constructed by applying and composing functions.
c) Database Programming Paradigm: Database programming model is used to manage data
and information structured as fields, records, and files.

5. What is meant by Structured Programming?


Structured Programming refers to the method of programming which consists of a completely structured
control flow. Here structure refers to a block, which contains a set of rules, and has a definitive control
flow, such as (if/then/else), (while and for), block structures, and subroutines.
Nearly all programming paradigms include Structured programming, including the Object Oriented
Programming model.

6. What are the main features of Object Oriented Programming?


Object Oriented Programming or Object Oriented Programming mainly comprises of the below four
features, and make sure you don't miss any of these:
Inheritance
Encapsulation
Polymorphism
Data Abstraction

2|Page
Campus: Prestige Vihar, Scheme No 74-C , Sector-D, Vijay Nagar Indore- 452010 M.P.
Phone : 0731-4013333, 4013334 Fax : 0731-4013329 website : www.piemr.edu.in
Department of Computer Science and Engineering (Accredited by National Board of Accreditation)

7. What are some advantages of using Object Oriented Programming?


Object Oriented Programming is very helpful in solving very complex level of problems.
Highly complex programs can be created, handled, and maintained easily using object-oriented
programming.
Object Oriented Programming, promote code reuse, thereby reducing redundancy.
Object Oriented Programming also helps to hide the unnecessary details with the help of Data
Abstraction.
Object Oriented Programming, are based on a bottom-up approach, unlike the Structural programming
paradigm, which uses a top-down approach.
Polymorphism offers a lot of flexibility in Object Oriented Programming.

8. Why is Object Oriented Programming so popular?


Object Oriented Programming paradigm is considered as a better style of programming. Not only it
helps in writing a complex piece of code easily, but it also allows users to handle and maintain them
easily as well. Not only that, the main pillar of Object Oriented Programming - Data Abstraction,
Encapsulation, Inheritance, and Polymorphism, makes it easy for programmers to solve complex
scenarios. As a result of these, Object Oriented Programming is so popular.

9. What is a class?
A class can be understood as a template or a blueprint, which contains some values, known as member
data or member, and some set of rules, known as behaviors or functions. So when an object is created,
it automatically takes the data and functions that are defined in the class.
Therefore the class is basically a template or blueprint for objects. Also one can create as many objects
as they want based on a class.
For example, first, a car’s template is created. Then multiple units of car are created based on that
template.

10. What is an object?


An object refers to the instance of the class, which contains the instance of the members and behaviors
defined in the class template. In the real world, an object is an actual entity to which a user interacts,
whereas class is just the blueprint for that object. So the objects consume space and have some
characteristic behavior.
For example, a specific car.

3|Page
Campus: Prestige Vihar, Scheme No 74-C , Sector-D, Vijay Nagar Indore- 452010 M.P.
Phone : 0731-4013333, 4013334 Fax : 0731-4013329 website : www.piemr.edu.in
Department of Computer Science and Engineering (Accredited by National Board of Accreditation)

11. What is encapsulation?


One can visualize Encapsulation as the method of putting everything that is required to do the job, inside
a capsule and presenting that capsule to the user. What it means is that by Encapsulation, all the
necessary data and methods are bind together and all the unnecessary details are hidden to the normal
user. So Encapsulation is the process of binding data members and methods of a program together to
do a specific job, without revealing unnecessary details.

Encapsulation can also be defined in two different ways:

1) Data hiding: Encapsulation is the process of hiding unwanted information, such as


restricting access to any member of an object.

2) Data binding: Encapsulation is the process of binding the data members and the methods
together as a whole, as a class.

12. What is Polymorphism?


Polymorphism is composed of two words - “poly” which means “many”, and “morph” which means
“shapes”. Therefore Polymorphism refers to something that has many shapes.
In Object Oriented Programming, Polymorphism refers to the process by which some code, data,
method, or object behaves differently under different circumstances or contexts. Compile-time
polymorphism and Run time polymorphism are the two types of polymorphisms in Object Oriented
Programming languages.

13. What is Compile time Polymorphism and how is it different from Runtime Polymorphism?
Compile Time Polymorphism: Compile time polymorphism, also known as Static Polymorphism,
refers to the type of Polymorphism that happens at compile time.
Runtime Polymorphism: Runtime polymorphism, also known as Dynamic Polymorphism, refers to
the type of Polymorphism that happens at the run time.

14. How does C++ support Polymorphism?


C++ is an Object-oriented programming language and it supports Polymorphism as well:
Compile Time Polymorphism: C++ supports compile-time polymorphism with the help of features
like templates, function overloading, and default arguments.

4|Page
Campus: Prestige Vihar, Scheme No 74-C , Sector-D, Vijay Nagar Indore- 452010 M.P.
Phone : 0731-4013333, 4013334 Fax : 0731-4013329 website : www.piemr.edu.in
Department of Computer Science and Engineering (Accredited by National Board of Accreditation)

Runtime Polymorphism: C++ supports Runtime polymorphism with the help of features like virtual
functions. Virtual functions take the shape of the functions based on the type of object in reference and
are resolved at runtime.
15. What is meant by Inheritance?
The term “inheritance” means “receiving some quality or behavior from a parent to an offspring.” In
object-oriented programming, inheritance is the mechanism by which an object or class (referred to as
a child) is created using the definition of another object or class (referred to as a parent). Inheritance
not only helps to keep the implementation simpler but also helps to facilitate code reuse.

16. What is Abstraction?


If you are a user, and you have a problem statement, you don't want to know how the components of
the software work, or how it's made. You only want to know how the software solves your problem.
Abstraction is the method of hiding unnecessary details from the necessary ones. It is one of the main
features of Object Oriented Programming.
For example, consider a car. You only need to know how to run a car, and not how the wires are
connected inside it. This is obtained using Abstraction.

17. How much memory does a class occupy?


Classes do not consume any memory. They are just a blueprint based on which objects are created. Now
when objects are created, they actually initialize the class members and methods and therefore consume
memory.

18. Is it always necessary to create objects from class?


No. An object is necessary to be created if the base class has non-static methods. But if the class has
static methods, then objects don’t need to be created. You can call the class method directly in this case,
using the class name.

19. What is a constructor?


Constructors are special methods whose name is the same as the class name. The constructors serve the
special purpose of initializing the objects.
For example, suppose there is a class with the name “MyClass”, then when you instantiate this class,
you pass the syntax:
MyClass myClassObject = new MyClass();

5|Page
Campus: Prestige Vihar, Scheme No 74-C , Sector-D, Vijay Nagar Indore- 452010 M.P.
Phone : 0731-4013333, 4013334 Fax : 0731-4013329 website : www.piemr.edu.in
Department of Computer Science and Engineering (Accredited by National Board of Accreditation)

Now here, the method called after “new” keyword - MyClass(), is the constructor of this class. This
will help to instantiate the member data and methods and assign them to the object myClassObject.

20. What are the various types of constructors in C++?


The most common classification of constructors includes:

Default constructor: The default constructor is the constructor which doesn’t take any argument. It
has no parameters.

class ABC
{
int x;

ABC()
{
x = 0;
}
}
Parameterized constructor: The constructors that take some arguments are known as parameterized
constructors.

class ABC
{
int x;

ABC(int y)
{
x = y;
}

6|Page
Campus: Prestige Vihar, Scheme No 74-C , Sector-D, Vijay Nagar Indore- 452010 M.P.
Phone : 0731-4013333, 4013334 Fax : 0731-4013329 website : www.piemr.edu.in
Department of Computer Science and Engineering (Accredited by National Board of Accreditation)

}
Copy constructor: A copy constructor is a member function that initializes an object using another
object of the same class.

class ABC
{
int x;

ABC(int y)
{
x = y;
}
// Copy constructor
ABC(ABC abc)
{
x = abc.x;
}
}
21. What is a copy constructor?
Copy Constructor is a type of constructor, whose purpose is to copy an object to another. What it means
is that a copy constructor will clone an object and its values, into another object, is provided that both
the objects are of the same class.

22. What is a destructor?


Contrary to constructors, which initialize objects and specify space for them, Destructors are also
special methods. But destructors free up the resources and memory occupied by an object. Destructors
are automatically called when an object is being destroyed.

23. Are class and structure the same? If not, what's the difference between a class and a structure?
No, class and structure are not the same. Though they appear to be similar, they have differences that
make them apart. For example, the structure is saved in the stack memory, whereas the class is saved
7|Page
Campus: Prestige Vihar, Scheme No 74-C , Sector-D, Vijay Nagar Indore- 452010 M.P.
Phone : 0731-4013333, 4013334 Fax : 0731-4013329 website : www.piemr.edu.in
Department of Computer Science and Engineering (Accredited by National Board of Accreditation)

in the heap memory. Also, Data Abstraction cannot be achieved with the help of structure, but with
class, Abstraction is majorly used.

24. Explain Inheritance?


Inheritance is one of the major features of object-oriented programming, by which an entity inherits
some characteristics and behaviors of some other entity and makes them their own. Inheritance helps to
improve and facilitate code reuse.

25. Are there any limitations of Inheritance?


Yes. Inheritance is a very powerful feature in Object Oriented Programming, but it has some limitations
too. Inheritance needs more time to process, as it needs to navigate through multiple classes for its
implementation. Also, the classes involved in Inheritance - the base class and the child class, are very
tightly coupled together. So if one needs to make some changes, they might need to do nested changes
in both classes. Inheritance might be complex for implementation, as well. So if not correctly
implemented, this might lead to unexpected errors or incorrect outputs.

26. What are the various types of inheritance?


The various types of inheritance include:
Single inheritance
Multiple inheritances
Multi-level inheritance
Hierarchical inheritance
Hybrid inheritance

27. What is a subclass?


The subclass is a part of Inheritance. The subclass is an entity, which inherits from another class. It is
also known as the child class.

28. Define a superclass?


Superclass is also a part of Inheritance. The superclass is an entity, which allows subclasses or child
classes to inherit from itself.

8|Page
Campus: Prestige Vihar, Scheme No 74-C , Sector-D, Vijay Nagar Indore- 452010 M.P.
Phone : 0731-4013333, 4013334 Fax : 0731-4013329 website : www.piemr.edu.in
Department of Computer Science and Engineering (Accredited by National Board of Accreditation)

29. What is an interface?


An interface refers to a special type of class, which contains methods, but not their definition. Only the
declaration of methods is allowed inside an interface. To use an interface, you cannot create objects.
Instead, you need to implement that interface and define the methods for their implementation.

30. What is meant by static polymorphism?


Static Polymorphism is commonly known as the Compile time polymorphism. Static polymorphism is
the feature by which an object is linked with the respective function or operator based on the values
during the compile time. Static or Compile time Polymorphism can be achieved through Method
overloading or operator overloading.

31. What is meant by dynamic polymorphism?


Dynamic Polymorphism or Runtime polymorphism refers to the type of Polymorphism in Object
Oriented Programming, by which the actual implementation of the function is decided during the
runtime or execution. The dynamic or runtime polymorphism can be achieved with the help of method
overriding.

32. What is the difference between overloading and overriding?


Overloading is a compile-time polymorphism feature in which an entity has multiple implementations
with the same name. For example, Method overloading and Operator overloading.
Whereas Overriding is a runtime polymorphism feature in which an entity has the same name, but its
implementation changes during execution. For example, Method overriding.
Image

33. How is data abstraction accomplished?


Data abstraction is accomplished with the help of abstract methods or abstract classes.

34. What is an abstract class?


An abstract class is a special class containing abstract methods. The significance of abstract class is that
the abstract methods inside it are not implemented and only declared. So as a result, when a subclass
inherits the abstract class and needs to use its abstract methods, they need to define and implement
them.

9|Page
Campus: Prestige Vihar, Scheme No 74-C , Sector-D, Vijay Nagar Indore- 452010 M.P.
Phone : 0731-4013333, 4013334 Fax : 0731-4013329 website : www.piemr.edu.in
Department of Computer Science and Engineering (Accredited by National Board of Accreditation)

35. How is an abstract class different from an interface?


Interface and abstract class both are special types of classes that contain only the methods declaration
and not their implementation. But the interface is entirely different from an abstract class. The main
difference between the two is that, when an interface is implemented, the subclass must define all its
methods and provide its implementation. Whereas when an abstract class is inherited, the subclass does
not need to provide the definition of its abstract method, until and unless the subclass is using it.
Also, an abstract class can contain abstract methods as well as non-abstract methods.

36. What are access specifiers and what is their significance?


Access specifiers, as the name suggests, are a special type of keywords, which are used to control or
specify the accessibility of entities like classes, methods, etc. Some of the access specifiers or access
modifiers include “private”, “public”, etc. These access specifiers also play a very vital role in achieving
Encapsulation - one of the major features of Object Oriented Programming.

37. What is an exception?


An exception can be considered as a special event, which is raised during the execution of a program at
runtime that brings the execution to a halt. 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.

38. What is meant by exception handling?


No one wants its software to fail or crash. Exceptions are the major reason for software failure. The
exceptions can be handled in the program beforehand and prevent the execution from stopping. This is
known as exception handling.
So exception handling is the mechanism for identifying the undesirable states that the program can
reach and specifying the desirable outcomes of such states.
Try-catch is the most common method used for handling exceptions in the program.

39. What is meant by Garbage Collection in Object Oriented Programming world?


Object-oriented programming revolves around entities like objects. Each object consumes memory and
there can be multiple objects of a class. So if these objects and their memories are not handled properly,
then it might lead to certain memory-related errors and the system might fail.
Garbage collection refers to this mechanism of handling the memory in the program. Through garbage
collection, the unwanted memory is freed up by removing the objects that are no longer needed.

10 | P a g e
Campus: Prestige Vihar, Scheme No 74-C , Sector-D, Vijay Nagar Indore- 452010 M.P.
Phone : 0731-4013333, 4013334 Fax : 0731-4013329 website : www.piemr.edu.in
Department of Computer Science and Engineering (Accredited by National Board of Accreditation)

40. Can we run a Java application without implementing the Object Oriented Programming
concept?
No. Java applications are based on Object-oriented programming models or Object Oriented
Programming concept, and hence they cannot be implemented without it.

41. What are the differences between object-oriented programming and structural programming?

Object-oriented Programming Structural Programming


It follows a bottom-up approach It follows a top-down approach.

It provides data hiding Data hiding is not allowed


It is used to solve complex problems It is used to solve moderate problems
It allows reusability of code that reduces Reusability of code is not allowed
redundancy of code
It is based on objects rather than functions and It provides a logical structure to a program in
procedures. which the program is divided into functions.

It provides more security as it has a data hiding It provides less security as it does not support
feature the data hiding feature.

More abstraction more flexibility Less abstraction less flexibility.


It focuses on data It focuses on the process or logical structure.

42. What is the concept of access specifiers when should we use these?

In OOPs language, access specifiers are reserved keyword that is used to set the accessibility of the
classes, methods and other members of the class. It is also known as access modifiers. It includes
public, private, and protected. There is some other access specifier that is language-specific. Such as
Java has another access specifier default. These access specifiers play a vital role in achieving one of
the major functions of OOP, i.e. encapsulation. The following table depicts the accessibility.

43. What are manipulators?

Manipulators are operators that are used to format the data display

44. Differentiate between procedural programming and object oriented programming?

Procedural Oriented Programming Object-Oriented Programming

It is based on functions It is based on real-world objects.


It follows a top-down approach It follows a bottom-up approach.

11 | P a g e
Campus: Prestige Vihar, Scheme No 74-C , Sector-D, Vijay Nagar Indore- 452010 M.P.
Phone : 0731-4013333, 4013334 Fax : 0731-4013329 website : www.piemr.edu.in
Department of Computer Science and Engineering (Accredited by National Board of Accreditation)

It is less secure because there is no proper way It provides more security.


to hide data
Data is visible to the whole program It encapsulates the data.
Reuse of code is not allowed The code can be reused.
Modification and extension of code are not easy We can easily modify and extend code.

Examples are C, VB, FORTRAN, Pascal, etc. Examples are C++, Java, C#, .NET, etc.

45) What is constructor chaining or Constructor Delegation?

In OOPs, constructor chaining is a sequence of invoking constructors (of the same class) upon
initializing an object. It is used when we want to invoke a number of constructors, one after another
by using only an instance. In other words, if a class has more than one constructor (overloaded) and
one of them tries to invoke another constructor, this process is known as constructor chaining. In C++,
it is also known as constructor delegation.

46) Name the operators that cannot be overload.

Scope Resolution Operator (::)

Ternary Operator (? :)

Member Access or Dot Operator (.)

Pointer to Member Operator (.*)

sizeof operator

47.What is the difference between class and struct in C++?

The primary difference is that members of a class have private access by default, while members of a
struct have public access by default.

48.Explain the concept of inheritance in C++.

Inheritance allows a class to inherit properties and behaviors from another class. It promotes code
reuse and establishes a relationship between base and derived classes.

49. What is polymorphism in C++?

Polymorphism allows objects of different types to be treated as objects of a common type. It includes
function overloading and overriding.

12 | P a g e
Campus: Prestige Vihar, Scheme No 74-C , Sector-D, Vijay Nagar Indore- 452010 M.P.
Phone : 0731-4013333, 4013334 Fax : 0731-4013329 website : www.piemr.edu.in
Department of Computer Science and Engineering (Accredited by National Board of Accreditation)

50. What is the difference between new and malloc() in C++?

new is an operator in C++ that also invokes the constructor, while malloc() is a function from C and
does not invoke constructors.

51. What is a virtual function in C++?

A virtual function is a function declared in a base class that can be overridden by a derived class. It
allows dynamic method binding.

52. How does encapsulation contribute to data hiding in C++?

Encapsulation bundles data and methods that operate on the data into a single unit, and it allows
access to the data through public methods while hiding the implementation details.

53. What is the difference between a class and an object in C++?

A class is a blueprint or template for creating objects. An object is an instance of a class, representing
a real-world entity.

54. Explain the concept of operator overloading in C++.

Operator overloading allows defining new behaviors for existing operators. For example, you can
overload the + operator to concatenate strings.

55. What is the purpose of the const qualifier in member functions?

The const qualifier in member functions indicates that the function does not modify the object's data
members. It is used for const-correctness.

56. How is a friend function different from a member function in C++?

A friend function is not a member of the class but has access to its private members. A member
function is a function declared within the class.

57. What is a constructor and destructor in C++?

A constructor is a special member function that initializes an object. A destructor is a special member
function that is called when an object goes out of scope.

58. Explain the concept of multiple inheritance in C++.

Multiple inheritance allows a class to inherit from more than one base class. It involves the use of
multiple parent classes.

59. How is a copy constructor different from an assignment operator?

A copy constructor is used to create a new object by copying the values of an existing object, while an
assignment operator is used to copy the values of one object to another.

60. What is a pure virtual function?

13 | P a g e
Campus: Prestige Vihar, Scheme No 74-C , Sector-D, Vijay Nagar Indore- 452010 M.P.
Phone : 0731-4013333, 4013334 Fax : 0731-4013329 website : www.piemr.edu.in
Department of Computer Science and Engineering (Accredited by National Board of Accreditation)

A pure virtual function is a virtual function with no implementation in the base class. It must be
implemented by any derived class before objects of that class can be instantiated.

61. How is runtime polymorphism achieved in C++?

Runtime polymorphism is achieved through the use of virtual functions and pointers or references to
base class objects.

62. What is the difference between early binding and late binding?

Early binding (static binding) occurs at compile-time, while late binding (dynamic binding) occurs at
runtime. Virtual functions enable late binding.

63. What is the purpose of the explicit keyword in C++?

The explicit keyword is used to prevent automatic type conversion by the compiler, particularly with
single-argument constructors.

64. Explain the role of the try, catch, and throw keywords in C++ exception handling.

try is used to enclose a block of code that may throw an exception. catch is used to handle exceptions,
and throw is used to throw an exception explicitly.

65. What is the purpose of the std::move function in C++11?

std::move is used to indicate that an object can be moved from, allowing for more efficient resource
management in certain situations.

66. How is dynamic polymorphism different from static polymorphism in C++?

Dynamic polymorphism (runtime polymorphism) involves the use of virtual functions, while static
polymorphism (compile-time polymorphism) is achieved through function overloading and templates.

67. What is the purpose of this pointer in C++?

The this pointer refers to the current instance of the class and is used to differentiate between the
class members and parameters with the same name.

----xxxx-----

14 | P a g e
Campus: Prestige Vihar, Scheme No 74-C , Sector-D, Vijay Nagar Indore- 452010 M.P.
Phone : 0731-4013333, 4013334 Fax : 0731-4013329 website : www.piemr.edu.in

You might also like