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

oops_interview_questions

The document provides a comprehensive overview of Object-Oriented Programming (OOP) concepts, including definitions, features, and differences between key terms such as classes, objects, inheritance, polymorphism, encapsulation, and abstraction. It also covers practical applications, access modifiers, and advanced topics like multiple inheritance and design patterns, along with common interview questions for freshers. The content is structured to aid understanding and preparation for OOP-related interviews.

Uploaded by

testdavid951
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

oops_interview_questions

The document provides a comprehensive overview of Object-Oriented Programming (OOP) concepts, including definitions, features, and differences between key terms such as classes, objects, inheritance, polymorphism, encapsulation, and abstraction. It also covers practical applications, access modifiers, and advanced topics like multiple inheritance and design patterns, along with common interview questions for freshers. The content is structured to aid understanding and preparation for OOP-related interviews.

Uploaded by

testdavid951
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

OOPs Interview Questions and Answers for Freshers

Basic OOPs Concepts


1. What is the difference between OOP and SOP?
2. Object-Oriented Programming Structural Programming
Provides a logical structure to a program
Based on objects rather than
Definition where programs are divided into
just functions and procedures.
functions.
Approach Bottom-up approach Top-down approach
Data Hiding Provides data hiding Does not provide data hiding
Problem Can solve problems of any
Can solve moderate problems
Complexity complexity
Code Code can be reused, thereby
Does not support code reusability
Reusability reducing redundancy.
3. What is Object-Oriented Programming?
Object-Oriented Programming (OOPs) is a type of programming based on objects rather than
just functions and procedures. Individual objects are grouped into classes. OOPs implements
real-world entities like inheritance, polymorphism, hiding, etc., into programming. It also
allows binding data and code together.
4. Why use OOPs?
o OOPs allows clarity in programming, thereby allowing simplicity in solving
complex problems.
o Code can be reused through inheritance, thereby reducing redundancy.
o Data and code are bound together by encapsulation.
o OOPs allows data hiding, therefore, private data is kept confidential.
o Problems can be divided into different parts, making them simpler to solve.
o The concept of polymorphism gives flexibility to the program by allowing entities
to have multiple forms.
5. What are the main features of OOPs?
o Inheritance
o Encapsulation
o Polymorphism
o Data Abstraction
6. What is an object?

An object is a real-world entity that is the basic unit of OOPs (e.g., chair, cat, dog, etc.).
Different objects have different states or attributes and behaviors.
7. What is a class?
A class is a prototype that consists of objects in different states and with different behaviors.
It has a number of methods common to the objects present within that class.
8. What is the difference between a class and a structure?
o Class: User-defined blueprint from which objects are created. It consists of
methods or sets of instructions that are to be performed on the objects.
o Structure: A structure is basically a user-defined collection of variables that are
of different data types.
9. Can you call the base class method without creating an instance?
Yes, you can call the base class without instantiating it if:
o It is a static method.
o The base class is inherited by some other subclass.
10. What is the difference between a class and an object?
Feature Object Class
A real-world entity that is an A template or blueprint within which
Definition
instance of a class. objects can be created.
Functionalit An object acts like a variable of Binds methods and data together into a
y the class. single unit.
Entity An object is a physical entity. A class is a logical entity.
Memory Objects take memory space when A class does not take memory space
Usage they are created. when created.
Objects can be declared as and
Declaration Classes are declared just once.
when required.
Inheritance
1. What is inheritance?
Inheritance is a feature of OOPs that allows classes to inherit common properties from other
classes. For example, if there is a class such as ‘vehicle’, other classes like ‘car’, ‘bike’, etc.,
can inherit common properties from the vehicle class. This property helps you get rid of
redundant code, thereby reducing the overall size of the code.
2. What are the different types of inheritance?
o Single inheritance
o Multiple inheritance
o Multilevel inheritance
o Hierarchical inheritance
o Hybrid inheritance
3. What is the difference between multiple and multilevel inheritance?
4. Multiple Inheritance Multilevel Inheritance
Definiti A class inherits from more than A class inherits from another class, which
on one base class. itself is a subclass of some other base class.
A class defining a child inherits A class describing a sports car will inherit
Exampl
from two base classes: Mother from a base class Car, which, in turn, inherits
e
and Father. another class Vehicle.
5. What is hybrid inheritance?
Hybrid inheritance is a combination of multiple and multi-level inheritance.
6. What is hierarchical inheritance?
Hierarchical inheritance refers to inheritance where one base class has more than one
subclass. For example, the vehicle class can have ‘car’, ‘bike’, etc., as its subclasses.
7. What are the limitations of inheritance?
o Increases the time and effort required to execute a program as it requires jumping
back and forth between different classes.
o The parent class and the child class get tightly coupled.
o Any modifications to the program would require changes both in the parent as
well as the child class.
o Needs careful implementation, else would lead to incorrect results.
8. What is a superclass?
A superclass or base class is a class that acts as a parent to some other class or classes. For
example, the Vehicle class is a superclass of class Car.
9. What is a subclass?
A class that inherits from another class is called the subclass. For example, the class Car is a
subclass or a derived class of the Vehicle class.
Polymorphism
1. What is polymorphism?
Polymorphism refers to the ability to exist in multiple forms. Multiple definitions can be given
to a single interface. For example, if you have a class named Vehicle, it can have a method
named speed, but you cannot define it because different vehicles have different speeds. This
method will be defined in the subclasses with different definitions for different vehicles.
2. What is static polymorphism?
Static polymorphism (static binding) is a kind of polymorphism that occurs at compile time.
An example of compile-time polymorphism is method overloading.
3. What is dynamic polymorphism?
Runtime polymorphism or dynamic polymorphism (dynamic binding) is a type of
polymorphism that is resolved during runtime. An example of runtime polymorphism is
method overriding.
4. What is method overloading?
Method overloading is a feature of OOPs that makes it possible to give the same name to
more than one method within a class if the arguments passed differ.
5. What is method overriding?
Method overriding is a feature of OOPs by which the child class or the subclass can redefine
methods present in the base class or parent class. Here, the method that is overridden has
the same name as well as the signature, meaning the arguments passed and the return type.
6. What is operator overloading?
Operator overloading refers to implementing operators using user-defined types based on the
arguments passed along with it.
7. Differentiate between overloading and overriding.
8. Overloading Overriding
Two or more methods having the Child class redefining methods present in
Definition same name but different the base class with the same
parameters or signature parameters/signature
Resolution
Resolved during compile-time Resolved during runtime
Time
Encapsulation & Abstraction
1. What is encapsulation?
Encapsulation refers to binding the data and the code that works on that together in a single
unit. For example, a class. Encapsulation also allows data-hiding as the data specified in one
class is hidden from other classes.
2. What are ‘access specifiers’?
Access specifiers or access modifiers are keywords that determine the accessibility of
methods, classes, etc., in OOPs. These access specifiers allow the implementation of
encapsulation. The most common access specifiers are public, private, and protected.
However, there are a few more which are specific to the programming languages.
3. What is the difference between public, private, and protected access
modifiers?
Accessibility from own Accessibility from derived Accessibility from the
Name
class class world
Public Yes Yes Yes
Private Yes No No
Protecte
Yes Yes No
d
4. What is data abstraction?
Data abstraction is a very important feature of OOPs that allows displaying only the important
information and hiding the implementation details. For example, while riding a bike, you know
that if you raise the accelerator, the speed will increase, but you don’t know how it actually
happens. This is data abstraction as the implementation details are hidden from the rider.
5. How to achieve data abstraction?
Data abstraction can be achieved through:
o Abstract class
o Abstract method
6. What is an abstract class?
An abstract class is a class that consists of abstract methods. These methods are basically
declared but not defined. If these methods are to be used in some subclass, they need to be
exclusively defined in the subclass.
7. Can you create an instance of an abstract class?
No. Instances of an abstract class cannot be created because it does not have a complete
implementation. However, instances of a subclass inheriting the abstract class can be
created.
8. What is an interface?
It is a concept of OOPs that allows you to declare methods without defining them. Interfaces,
unlike classes, are not blueprints because they do not contain detailed instructions or actions
to be performed. Any class that implements an interface defines the methods of the interface.
9. Differentiate between data abstraction and encapsulation.
10. Data abstraction Encapsulation
Problem Solves the problem at the design Solves the problem at the
Level level implementation level
Functionali Allows showing important aspects Binds code and data together into a
ty while hiding implementation details single unit and hides it from the world
Methods & Functions
1. What are virtual functions?
Virtual functions are functions that are present in the parent class and are overridden by the
subclass. These functions are used to achieve runtime polymorphism.
2. What are pure virtual functions?
Pure virtual functions or abstract functions are functions that are only declared in the base
class. This means that they do not contain any definition in the base class and need to be
redefined in the subclass.
3. What is a constructor?
A constructor is a special type of method that has the same name as the class and is used to
initialize objects of that class.
4. What is a destructor?
A destructor is a method that is automatically invoked when an object is destroyed. The
destructor also recovers the heap space that was allocated to the destroyed object, closes the
files and database connections of the object, etc.
5. What are the types of constructors?
Types of constructors differ from language to language. However, all the possible constructors
are:
o Default constructor
o Parameterized constructor
o Copy constructor
o Static constructor
o Private constructor
6. What is a copy constructor?
A copy constructor creates objects by copying variables from another object of the same
class. The main aim of a copy constructor is to create a new object from an existing one.
7. What is the use of ‘finalize’?
Finalize is an object method used to free up unmanaged resources and cleanup before
Garbage Collection (GC). It performs memory management tasks.
8. What is Garbage Collection(GC)?
GC is an implementation of automatic memory management. The Garbage collector frees up
space occupied by objects that are no longer in existence.
9. Differentiate between a class and a method.
10.
Class Method
A template that binds the Callable set of instructions, also called a
Definiti
code and data together into a procedure or function, that are to be performed
on
single unit. on the given data
Content Classes consist of methods,
s variables, etc.
11. Differentiate between an abstract class and an interface?
Basis for comparison Abstract Class Interface
Can have abstract as well as
Methods Only abstract methods
other methods
May contain final and non- Variables declared are final by
Final Variables
final variables default
Accessibility of
Can be private, public, etc. Public by default
Data Members
Can provide the Cannot provide the
Implementation implementation of an implementation of an abstract
interface class
12. What is a final variable?
A variable whose value does not change. It always refers to the same object by the property
of non-transversity.
Exception Handling
1. What is an exception?
An exception is a kind of notification that interrupts the normal execution of a program.
Exceptions provide a pattern to the error and transfer the error to the exception handler to
resolve it. The state of the program is saved as soon as an exception is raised.
2. What is exception handling?
Exception handling in Object-Oriented Programming is a very important concept that is used
to manage errors. An exception handler allows errors to be thrown and caught and
implements a centralized mechanism to resolve them.
3. What is the difference between an error and an exception?
4. Error Exception
Definiti Problems that should not be encountered Conditions that an application
on by applications might try to catch
5. What is a try/catch block?
A try/catch block is used to handle exceptions. The try block defines a set of statements that
may lead to an error. The catch block basically catches the exception.
6. What is a finally block?
A finally block consists of code that is used to execute important code such as closing a
connection, etc. This block executes when the try block exits. It also makes sure that the
finally block executes even in case some unexpected exception is encountered.
Limitations
1. What are the limitations of OOPs?
o Usually not suitable for small problems.
o Requires intensive testing.
o Takes more time to solve the problem.
o Requires proper planning.
o The programmer should think of solving a problem in terms of objects.
Important Note: Due to my limitations as a language model, I cannot directly create a .docx
file for you. However, you can easily copy and paste this text into a Microsoft Word document
(or any other word processor) and save it as a .docx file.
In interviews focusing on Object-Oriented Programming (OOP), candidates are often asked a variety of questions to
assess their understanding of fundamental concepts and their practical applications. Common topics include:

1. Fundamental OOP Concepts:


o Encapsulation: Definition and its significance in restricting direct access to some of an object's
components.
o Inheritance: Understanding how a class can inherit properties and methods from another class,
promoting code reusability.
o Polymorphism: Explanation of how different classes can be treated as instances of the same class
through interfaces or inheritance, allowing for methods to perform differently based on the object they
are acting upon.
o Abstraction: Discussing the concept of hiding complex implementation details and showing only the
necessary features of an object.
2. Differences Between Key Concepts:
o Class vs. Object: Clarifying that a class is a blueprint for objects, while an object is an instance of a
class.
o Overloading vs. Overriding: Differentiating between having multiple methods with the same name
but different parameters (overloading) and redefining a base class's method in a derived class
(overriding).
3. Access Modifiers:
o Understanding the roles of private, protected, and public access modifiers in controlling the visibility
and accessibility of class members.
4. Real-World Applications:
o Providing examples of how OOP principles are applied in real-world scenarios, such as modeling a
car's behavior and attributes in a software application.
5. Advanced Topics:
o Multiple Inheritance: Discussing how some languages allow a class to inherit from more than one
base class and the complexities involved.
o Interfaces and Abstract Classes: Explaining the purpose of interfaces and abstract classes in
providing a contract for other classes to implement.
6. Design Patterns:
o Understanding common design patterns like Singleton, Factory, and Observer, which provide solutions
to recurring design problems.

These questions aim to evaluate a candidate's theoretical knowledge and their ability to apply OOP principles
effectively in software development.

You might also like