Top 50 OOPs Interview Questions and Answers in 2024

Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism etc. in programming. The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function. OOP allows objects to interact with each other using four basic principles: encapsulation, inheritance, polymorphism, and abstraction. These four OOP principles enable objects to communicate and collaborate to create powerful applications The dictionary meaning of an object is "an entity that exists in the real world", and oriented means "interested in a particular kind of thing or entity". In basic terms, OOP is a programming pattern that is built around objects or entities, so it's called object-oriented programming

OOPs Interview Questions in Agn Hub

Object-Oriented Programming is one of the main concepts in the programming world, therefore, every interview that you attend requires knowledge of OOPs. This article compiles the most frequently asked OOPs Interview Questions for freshers which will help you ace your interviews. So go ahead and get prepared.


1) What is OOPS?

OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class

2) Write basic concepts of OOPS?

Basic Concepts of OOPs Polymorph sm Encapsulation Data Abstraction

3) What is a class?

c ass •s strop y a representaüon o a typeo o rct. t IS t e ueptunt/p an teniP ate t nat describes the details of an 0b'ect.

4) What is an Object?

An object is an instance of a class It has its own state behavior and identity.

5) What is Encapsulation?

Encapsulation is an attribute o an object and it contains a data which is hidden. That hidden data can be restricted to the members of that class. Levels are Public Protected Private Internal and Protected Internal.

6) What is Polymorphism?

Polymorphism is nothing but assigning behavior or value in a subclass to something that was already declared in the main class. Simply polymorphism takes more than one form.

7) What is Inheritance?

Manipulators are the functions which can be used in conjunction with the insertion (< <) and extraction (y y) operators on an object. Examples are endl and setw.

8) What are manipulators?

es ruc or IS a me o w IC IS au oma Ica y ca w en e o jec IS ma e o scope or destroyed Destructor name is also same as class name but with the tilde symbol before the name.

9) Explain the term constructor?

A virtual function is a member function Of a class and its functionality can be overridden in its derived class. This function can be implemented by using a keyword called virtual and it can be given during function declaration. A virtual function can be declared using a token(virtual) in C++. It can be achieved in C/Python Language by using function pointers or pointers to function.

10) Define Destructor?

A friend function is a friend of a class that is allowed to access to Public private or protected data in that same class. If the function is defined outside the class cannot access such information. A friend can be declared anywhere in the class declaration and it cannot be affected br access control keywords like private public or protected.

11) What is an Inline function?

Function overloading is a regular function but it is assigned with multiple parameters. It allows the creation of several methods with the same name which differ from each other by the type of input and output of the function. Example void void void a int& b); add (double' a double& b) ; add (struct bob& a struct hob & b); Operator Overloading Function Overloading

12) What is a virtual function?

perator over oa I ng IS a unction w ere I erent operators are app le an epen son the arguments. Operator - ' can be used to pass through the function and it has its own recedence to execute

13) What is a friend function?

An abstract class is a class which cannot be instantiated Creation of an object is not possible with an abstract class but it can be inherited. An abstract class can contain only an Abstract method. Java allows only abstract method in abstract class while other languages allow non-abstract method as well. The ternary operator is said to be an operator which takes three arguments. Arguments and results are of different data types and it depends on the function. The ternary operator is also called a conditional operator.

Finalize method helps to perform cleanup operations on the resources which are not currently used. Finalize method is protected and it is accessible only through this clasd a derived class

14) What is function overloadin?

A parameter is a variable used during the declaration of the function or subroutine and arguments are passed to the function body and it should match with the parameter defined. There are two types of Arguments • 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 in both inside and outside the functions and it returns the same or different value.

15) What is operator overloading?

The super keyword is used to invoke the overridden method which overrides one Of its superclass methods. This keyword allows to access overridden methods and also to access hidden members of the superclass It also forwards a call from a constructor to a constructor in the superclass

16) What is an abstract class?

Method overriding is a feature that allows a subclass to provide the implementation of a method that overrides in the main class. It will override the implementation in the superclass by providing the same method name same parameter and same return type.

17) What is a ternary operator?

An interface is a collection of an abstract method. If the class implements an interface it thereby inherits all the abstract methods of an interface. Java uses Interface to implement multiple inheritances.

18) What is the use Of finalize method?

An exception is an event that occurs during the execution of a program. Exceptions can be of any type — Runtime exception Error exceptions. Those exceptions are adequately handled through exception handling mechanism like try catch and throw keywords.

19) What are the different types of arguments?

A comp er recognizes a to en an It cannot e ro en own Into component e ements. Keywords identifiers constants string literals and operators are examples of tokens Even punctuation characters are also considered as tokens. Example: Brackets Commas Braces and Parentheses.

20) What is the super keyword?

Overloading is static Binding whereas Overriding is dynamic Binding. Overloading is nothing but the same method with different arguments and it may or may not return the equal value in the same class itself. Overriding is the same method names with the same arguments and return types associated with the class and its child class.

21) What is method overriding?

An object is an instance of a class. Objects hold multiple information but classes don't hav any information. Definition of properties and functions can be done in class and can be use by the object. A class can have sub-classes while an object doesn't have sub-objects.

22) What is an interface?

stractlon IS a use u eature 0 an Its ows ony e necessary etal s to e c lent of an object. Meaning it shows only required details for an object not the inner constructors of an object. Example — When you want to switch on the television it is not necessary to know the inner circuitry/mechanism needed to switch on the TV. Whatever is re uired to switch on TV will be shown usin an abstract class.

23) What is exception handling?

Access modifiers determine the scope of the method or variables that can be accessed from Other various objects or classes. There are five types Of access modifiers and they are as follows: Access Modifiers • • • Private Public Friend Default Visible to the package. the default. No modifiers are public Visible to the world protected Visible to the package and all subclasses private Visible to the class only

24) What are tokens?

Sealed modifiers are the access modifiers where the methods can not inherit it. Sealed modifiers can also be applied to properties events and methods. This modifier cannot be used to static members

25) What is the main difference between overloading and overriding?

Yes it is possible to call the base method without creating an instance. And that method should be "Static method."

26) What is the main difference between a class and an object?

The new modifier instructs the compiler to use the new implementation instead of the base class function. Whereas Override modifier helps to override the base class function.

27) What is an abstraction?

There are three types of constructors: Default Constructor — With no parameters. — Parametric Constructor — With Parameters. Create a new instance of a class and also passing arguments simultaneously. Copy Constructor — Which creates a new object as a copy of an existing object.

28) What are the access modifiers?

Early binding refers to the assignment Of values to variables during design time whereas late Binding refers to the assignment of values to variables during run time.

29) What are sealed modifiers?

pointer re ers o e curren o J eywor IS use as a pointer w IC a c ass. differentiates between the current object with the global object. It refers to the current object.

30) How can we call the base method without creating an instance?

The default access type of a Structure is public but class access type is private. A structure is used for grouping data whereas a class can be used for grouping data and methods. Structures are exclusively used for data and it doesn't require strict validation but classes are used to encapsulate and inherent data which requires strict validation.

31) What is the difference between new and override?

The default access modifier of a class is Internal and the default access modifier of a class member is Private.

32) What are the various types of constructors?

A pure virtual function is a function which can be overridden in the derived class but ca be defined. A virtual function can be declared as Pure by using the operator —O. Example — Virtual void functionl ( ) // Virtual Not pure Virtual void function2() = O // Pure virtual

33) What is early and late Binding?

1. Scope Resolution (::) 2. Member Selection (.) 3. Member selection through a pointer to function (.*)

34) What is 'this' pointer?

Dynamic or Run time polymorphism is also known as method overriding in which call to an overridden function is resolved during run timer not at the compile time It means haviA+ two or more methods with the same name same signature but with different implementation.

35) What is the difference between structure and a class?

No we do not require a parameter for constructors

36) What is the default access modifier in a class?

This is a special constructor for creating a new object as a copy of an existing object. There will always be only one copy constructor that can be either defined by the user or the system.

37) What is a pure virtual function?

It means we can override the method.

38) What are all the operators that cannot be overloaded?

false

39) What is dynamic or run time polymorphism?

The base class is the most generalized class and it is said to be a root class. A Subclass is a class that inherits from one or more base classes. The superclass is the parent class from which another class inherits.

40) Do we require a parameter for constructors?

Binding is nothing but the association of a name with the class. Static Binding is a binding in which name can be associated with the Class during compilation time and it is also called as early Binding. Dynamic Binding is a binding in which name can be associated with the class during execution time and it is also called as Late Binding.

41) What is a copy constructor?

Zero instances will be created for an abstract class. In other words you cannot create an instance of an Abstract Class.

42) What does the keyword virtual represented in the method definition?

perator eywor IS use or over oa Ing-

43) Whether static method can use nonstatic members?

Private access specifier is used in a class definition.

44) What are a base class subclass and superclass?

Inheritance is the OOPS concept that can be used as a reuse mechanism.

45) What is static and dynamic Binding?

Encapsulation Encapsulation • The wrapping up of data and function together into a single unit is called encapsulation. class hanction • This feature keeps the data safe from outside interference and misuse. This led to a concept of Data hiding. • In programming language like encapsulation is achieved through user defined data type classes.

46) How many instances can be created for an abstract class?

Binding is nothing but the association of a name with the class. Static Binding is a binding in which name can be associated with the Class during compilation time and it is also called as early Binding. Dynamic Binding is a binding in which name can be associated with the class during execution timer and it is also called as Late Binding

47) Which keyword can be used for overloading?

ero Ins anceswl e creae or ana s rac cass. no wor s you canno crea e an instance of an Abstract Class

48) What is the default access specifier in a class definition?

Operator keyword is used for overloading.

49) Which OOPS concept is used as a reuse mechanism?

Private access specifier is used in a class definition.

50) Which OOPS concept exposes only the necessary information to the calling functions?.

Inheritance is the OOPS concept that can be used as a reuse mechanism. Encapsulation Encapsulation The wrapping up of data and function together into a single unit is called encapsulation. class function • This feature keeps the data safe from outside interference and misuse. This led to a concept of Data hiding. • In programming language like encapsulation is achieved through user defined data type classes.