OOPS Interview Questions and Answers 2022
OOPS Interview Questions and Answers 2022
Profile
Freshers 2022
In this page you will find the most asked OOPS Interview questions for Freshers. Go through them to know
what OOPS Interview questions are being asked to freshers in 2022 and prepare for your interview with us.
Page Highlights:
What is OOPS?
Most Asked OOPS Interview Questions for Freshers
Object oriented programming uses paradigm that organizes software architecture around files rather than functions and logics. An object is a data field with
its own set of attributes and actions. The fundamental idea behind OOPS is to reuse objects throughout the program.
What is a class?
A class is nothing more than a description of an object. It is a model, design, or prototype that describes an object’s features.
What is an object?
An object is termed as an instance of a class, and it has its own state, behavior, and identity.
Define a constructor.
A constructor is a method used to initialize the state of an object, and it gets invoked at the time of object creation.
when a class inherits more than one base class when a class inherits from another class which itself is a subclass of
some other base class
Example:-
A class defining a child inherits from Example:-
A class describing a sport car will inherit from one base class
two base classes Mother and Father car which in turn inherits another class Vehicle
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. or, BMW is a type of car, so the superclass for BMW is Class Car.
overloading overriding
two or more methods have same name but child class redefining methods present in the base class or parent class
different parameters or signatures with the same parameters/signatures
Finalize is a method used to free up unmanaged resources and cleanup before Garbage Collection(GC). It performs memory
management tasks.
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.
https://prepinsta.com/interview-preparation/technical-interview-questions/oops/ 1/7
11/10/22, 9:53 AM OOPS Interview Questions and Answers 2022 | PrepInsta
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.
What is Encapsulation?
Encapsulation is a feature of an entity that holds all secret data. The members of that class can only see the hidden details. Public,
Protected, Private are the different levels.
Inheritance is a concept where one class shares the structure and behavior defined in another class. Inheritance applied to one
class is called Single Inheritance, and if it depends on multiple classes, then it is called multiple Inheritance.
Uses:-
Static Binding is a binding in which the name can be combined with the class during collection time, and it is also called early
binding.
Dynamic Binding is a binding in which name can be identified with the class during execution time, and it is also known as Late
Binding.
Can you call the base class method without creating an instance?
Yes, it is possible to call the base method without creating an instance. And that method should be the static method. Doing
inheritance from that class use the Base Keyword from a derived class.
Constructors Methods
constructor name should match with the name of the class Methods should not have the same name as the class
name
used to initialize and allocate memory of to the object used to execute certain statements written inside them
constructors are invoked by the system whenever objects are invoked when it is called
created
they are invoked using new keyword while creating an instance of invoked during program execution
the class
Abstract Class:-
An object cannot be inherited from the abstract class.
Subclass created or inherit abstract class to access members of the abstract class.
An abstract class can contain abstract methods or non-abstract methods.
Abstract Method:-
An abstract method has a signature but does not have a body
It is compulsory to override abstract methods of the superclass in their sub-class
Class containing abstract method should be made abstract class
Extends Implements
A class can extend another class interface A class can implement an interface
A subclass extending superclass may not override all of the A class implementing interface has to implement all the
superclass methods methods of the interface
A class can only extend a single superclass A class can implement any number of interfaces 6
An interface can extend more than one interfaces An interface cannot implement any other interface
https://prepinsta.com/interview-preparation/technical-interview-questions/oops/ 2/7
11/10/22, 9:53 AM OOPS Interview Questions and Answers 2022 | PrepInsta
What is a destructor?
It is a method which is called when the object is destroyed. Destructor name is the same as class name with “~” symbol before the
name.
Virtual function is a special member function that is declared within a base class and redefined by derived class to go with its own
task. It is declared using a token, and is implemented by using the virtual keyword.
A friend function is capable of accessing private/protected data of a class in which it is declared as a friend in spite of not being a
member of that class.
Abstract classes are special classes which are declared but are initialized, which means that it is not possible to create an object
for the abstract class.
Access specifiers are used to hide or show data to the end user. It is used in data hiding or data abstraction.
What is casting?
In C++ we create a pointer reference between parent and child classes and form an “is a” relationship between them, This is known
as casting and they are of two types:-
Upcasting
Downcasting
Run time polymorphism helps resolve the problem of early binding at compile time.
#include <stdio.h>
6
class Base
{
https://prepinsta.com/interview-preparation/technical-interview-questions/oops/ 3/7
11/10/22, 9:53 AM OOPS Interview Questions and Answers 2022 | PrepInsta
{
public:
};
public:
void show()
};
int main()
Base *base_object;
Derived derived_object;
base_object = &derived_object;
base_object->show();
return 0;
These are the special type of constructors which takes an object as an argument and uses it to copy value of data members of one
object to another object.
Access modifiers are used to figure out the scope of the method or variables accessible from other various objects or classes.
Private
Public
Protected
Friend
Protected Friend
What is Abstraction?
Abstraction refers to revealing only the most important information while concealing the details. Data abstraction refers to exposing
only the most important aspects of the data to the outside world while concealing the implementation information.
Increases the time and effort required to execute a program as it requires jumping back and forth between different classes
The parent class and the child class get tightly coupled
Any modifications to the program would require changes both in the parent as well as the child class
Needs careful implementation else would lead to incorrect results
Abstraction Encapsulation
Gives a class a general structure and leaves the Creates and defines an object’s permissions and constraints as well as the
implementation to the implementers. variables and methods that make up the object.
Abstraction is accomplished by the use of an Encapsulation is accomplished by the use of four different access level
interface and an abstract class. modifiers: public, protected, no modifier and private.
Class Structure
CLR allocates memory for its instance in Memory is allocated on the stack.
heap.
Variables of a class can be assigned as Structure members cannot have null values. 6
null.
Class can contain constructor/destructor Structure does not require constructor/destructor and members can be initialized
https://prepinsta.com/interview-preparation/technical-interview-questions/oops/ 4/7
11/10/22, 9:53 AM OOPS Interview Questions and Answers 2022 | PrepInsta
q
automtaically.
Class Structure
Get 200+ Courses under 1 Subscription just @3999 Checkout Prime
A parameter is a variable used during the declaration of the function or subroutine and arguments are passed to the function, and it
should match with the parameter defined.
Call by Value – Value passed will get modified only inside the function, and it returns the same value whatever it is passed into the
function.
Call by Reference – Value passed will get modified both inside and outside the functions and it returns the same or different
value.
Java was designed to be a simple language and multiple inheritance introduces complexities like the diamond problem. Inheriting
states or behaviors from two different type of classes is a case which in reality very rare and it can be achieved easily through an
object association.
The following are some of the similarities between a class and a structure:
Access specifiers, such as public, private, and protected, are identically used in structures and classes to restrict the access of
their data and methods outside their body.
The access level for class members and struct members, including nested classes and structs, is private by default. Private
nested types are not accessible from outside the containing type.
Both can have constructors, methods, properties, fields, constants, enumerations, events, and event handlers.
Both structures and classes can implement interfaces to use multiple-inheritance in code.
Both structures and classes can have constructors with parameters.
Both structures and classes can have delegates and events.
Java is not an entirely pure object-oriented programming language. The following are the reasons:
Java supports and uses primitive data types such as int, float, double, char, etc.
Primitive data types are stored as variables or on the stack instead of the heap.
In Java, static methods can access static variables without using an object, contrary to object-oriented concepts.
Encapsulation is a feature of an entity that holds all secret data. The members of that class can only see the hidden details. Public,
Protected, Private are the different levels.
Single Inheritance: Single child class inherits characteristics of the single-parent class.
Multiple Inheritance: One class inherits features of more than one base class and is not supported in Java, but the class can
implement more than one interface.
Multilevel Inheritance: A class can inherit from a derived class making it a base class for a new class, for example, a Child inherits
behavior from his father, and the father has inherited characteristics from his father.
Hierarchical Inheritance: One class is inherited by multiple subclasses.
Hybrid Inheritance: This is a combination of single and multiple inheritances.
What is Interface?
In general, an interface is a system that allows two or more unrelated entities to communicate. According to this definition, remote
control is an interface between you and a television set, the English language is an interface between two people, and the protocol of
behavior enforced in the military is the interface between people of different ranks.
Within the Java programming language, an interface (in the glossary) is a type, just as a class is a type. Like a class, an interface
defines methods. Unlike a class, an interface never implements methods; instead, classes that implement the interface implement
the methods defined by the interface. A class can implement multiple interfaces.
Default Constructor: The default constructor is the constructor which does not take any argument. It has no parameters.
class A
int x;
A()
x = 0;
} 6
Parameterized constructor: The constructors that take some arguments are known as parameterized constructors.
https://prepinsta.com/interview-preparation/technical-interview-questions/oops/ 5/7
11/10/22, 9:53 AM OOPS Interview Questions and Answers 2022 | PrepInsta
int x;
A(int y)
x = y;
Copy constructor: A copy constructor is a member function that initializes an object using another object of the same class.
class A
int x;
A(int y)
x = y;
// Copy constructor
A(A a)
{
x = a.x;
Answer:-
https://prepinsta.com/interview-preparation/technical-interview-questions/oops/ 6/7