4 Object Oriented Programming Interview Questions
4 Object Oriented Programming Interview Questions
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)
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)
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.
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)
2) Data binding: Encapsulation is the process of binding the data members and the methods
together as a whole, as a class.
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.
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.
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.
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.
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.
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)
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)
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?
It provides more security as it has a data hiding It provides less security as it does not support
feature the data hiding feature.
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.
Manipulators are operators that are used to format the data display
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)
Examples are C, VB, FORTRAN, Pascal, etc. Examples are C++, Java, C#, .NET, etc.
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.
Ternary Operator (? :)
sizeof operator
The primary difference is that members of a class have private access by default, while members of a
struct have public access by default.
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.
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)
new is an operator in C++ that also invokes the constructor, while malloc() is a function from C and
does not invoke constructors.
A virtual function is a function declared in a base class that can be overridden by a derived class. It
allows dynamic method binding.
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.
A class is a blueprint or template for creating objects. An object is an instance of a class, representing
a real-world entity.
Operator overloading allows defining new behaviors for existing operators. For example, you can
overload the + operator to concatenate strings.
The const qualifier in member functions indicates that the function does not modify the object's data
members. It is used for const-correctness.
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.
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.
Multiple inheritance allows a class to inherit from more than one base class. It involves the use of
multiple parent classes.
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.
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.
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.
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.
std::move is used to indicate that an object can be moved from, allowing for more efficient resource
management in certain situations.
Dynamic polymorphism (runtime polymorphism) involves the use of virtual functions, while static
polymorphism (compile-time polymorphism) is achieved through function overloading and templates.
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