1. What is Object Oriented Programming (OOPs)?
OOP stands for Object-Oriented Programming, a computer programming model that organizes
software design around objects instead of logic and functions. 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.
[Link] OOPs?(Advantage)
Object-oriented programming has several advantages over procedural programming:
OOP is faster and easier to execute
OOP provides a clear structure for the programs
OOP helps to keep the C++ code DRY "Don't Repeat Yourself", and makes the code easier to
maintain, modify and debug
OOP makes it possible to create full reusable applications with less code and shorter
development time
3. What is a Class?
A class is a building block of Object Oriented Programs. It is a user-defined data type that contains
the data members and member functions that operate on the data members. It is like a blueprint or
template of objects having common properties and methods.
4. What is an Object?
An object is an instance of a class. Data members and methods of a class cannot be used directly. We
need to create an object (or instance) of the class to use them. In simple terms, they are the actual
world entities that have a state and behavior.
5. What are the main features of OOPs?
The main feature of the OOPs, also known as 4 pillars or basic principles of OOPs are as follows:
1. Encapsulation
2. Data Abstraction
3. Polymorphism
4. Inheritance
6. What is Encapsulation?
Encapsulation is the binding of data and methods that manipulate them into a single unit such that
the sensitive data is hidden from the users
It is implemented as the processes mentioned below:
1. Data hiding: A language feature to restrict access to members of an object. For example,
private and protected members in C++.
2. Bundling of data and methods together: Data and methods that operate on that data are
bundled together. For example, the data members and member methods that operate on
them are wrapped into a single unit known as a class.
3. 7. What is Abstraction?
4. Abstraction is similar to data encapsulation and is very
important in OOP. It means showing only the necessary
information and hiding the other irrelevant information
from the user. Abstraction is implemented using classes
and interfaces.
8. What is Polymorphism?
The word “Polymorphism” means having many forms. It is the property of some code to behave
differently for different contexts. For example, in C++ language, we can define multiple functions
having the same name but different working depending on the context.
Polymorphism can be classified into two types based on the time when the call to the object or
function is resolved. They are as follows:
Compile Time Polymorphism
Runtime Polymorphism
A) Compile-Time Polymorphism
Compile time polymorphism, also known as static polymorphism or early binding is the type of
polymorphism where the binding of the call to its code is done at the compile time. Method
overloading or operator overloading are examples of compile-time polymorphism.
B) Runtime Polymorphism
Also known as dynamic polymorphism or late binding, runtime polymorphism is the type of
polymorphism where the actual implementation of the function is determined during the runtime or
execution. Method overriding is an example of this method.
9. What is Inheritance? What is its purpose?
The idea of inheritance is simple, a class is derived from another class and uses data and
implementation of that other class. The class which is derived is called child or derived or subclass
and the class from which the child class is derived is called parent or base or superclass.
The main purpose of Inheritance is to increase code reusability. It is also used to achieve Runtime
Polymorphism.
10. What are access specifiers? What is their significance in OOPs?
Access specifiers are special types of keywords that are used to specify or control the accessibility of
entities like classes, methods, and so on. Private, Public, and Protected are examples of access
specifiers or access modifiers.
11. What are the advantages and disadvantages of OOPs?
Advantages of OOPs Disadvantages of OOPs
OOPs provides enhanced code The programmer should be well-skilled and should
Advantages of OOPs Disadvantages of OOPs
have excellent thinking in terms of objects as
reusability.
everything is treated as an object in OOPs.
The code is easier to maintain and Proper planning is required because OOPs is a little
update. bit tricky.
It provides better data security by
restricting data access and avoiding OOPs concept is not suitable for all kinds of problems.
unnecessary exposure.
Fast to implement and easy to redesign
The length of the programs is much larger in
resulting in minimizing the complexity
comparison to the procedural approach.
of an overall program.
16. What is the difference between overloading and overriding?
A compile-time polymorphism feature called overloading allows an entity to have numerous
implementations of the same name. Method overloading and operator overloading are two
examples.
Overriding is a form of runtime polymorphism where an entity with the same name but a different
implementation is executed. It is implemented with the help of virtual functions.
Are there any limitations on Inheritance?
Yes, there are more challenges when you have more authority. Although inheritance is a very strong
OOPs feature, it also has significant drawbacks.
As it must pass through several classes to be implemented, inheritance takes longer to
process.
The base class and the child class, which are both engaged in inheritance, are also closely
related to one another (called tightly coupled). Therefore, if changes need to be made, they
may need to be made in both classes at the same time.
Implementing inheritance might be difficult as well. Therefore, if not implemented correctly,
this could result in unforeseen mistakes or inaccurate outputs.
18. What different types of Inheritance are there?
1. Single Inheritance: Child class derived directly from the base class
2. Multiple Inheritance: Child class derived from multiple base classes.
3. Multilevel Inheritance: Child class derived from the class which is also derived from another
base class.
4. Hierarchical Inheritance: Multiple child classes derived from a single base class.
5. Hybrid Inheritance: Inheritance consisting of multiple inheritance types of the above
specified.
24. What is Constructor?
A constructor is a block of code that initializes the newly created object. A constructor resembles an
instance method but it’s not a method as it doesn’t have a return type. It generally is the method
having the same name as the class but in some languages, it might differ.
25. What are the various types of constructors in C++?
The most common classification of constructors includes:
1. Default Constructor
2. Non-Parameterized Constructor
3. Parameterized Constructor
4. Copy Constructor
1. Default Constructor
The default constructor is a constructor that doesn’t take any arguments. It is a non-parameterized
constructor that is automatically defined by the compiler when no explicit constructor definition is
provided.
It initializes the data members to their default values.
2. Non-Parameterized Constructor
It is a user-defined constructor having no arguments or parameters.
3. Parameterized Constructor
The constructors that take some arguments are known as parameterized constructors.
4. Copy Constructor
A copy constructor is a member function that initializes an object using another object of the same
class.
[Link] is a destructor?
A destructor is a method that is automatically called when the object is made of scope or destroyed.
In C++, the destructor name is also the same as the class name but with the (~) tilde symbol as the
prefix.
[Link] is the virtual function?
A virtual function is a function that is used to override a method of the parent class in the derived
class. It is used to provide abstraction in a class.
In C++, a virtual function is declared using the virtual keyword,
30. What is pure virtual function?
A pure virtual function, also known as an abstract function is a member function that doesn’t contain
any statements. This function is defined in the derived class if needed.
[Link] is an abstract class?
A class having more than 2 virtual functions
an abstract class is a class that contains at least one pure virtual function.