C
C
function with the same name, but different in parameters is known as function overloading in C++. In
function overloading, the function is redefined by using either different types of arguments or a different
number of arguments. It is only through these differences compiler can differentiate between the
functions./ Operator overloading is a compile-time polymorphism. For example, we can overload an
operator ‘+’ in a class like String so that we can concatenate two strings by just using +. Other example
classes where arithmetic operators may be overloaded are Complex Numbers, Fractional Numbers, Big
integers, etc.// Example:/int a;/float b,sum;/sum = a + b;/// Here, variables “a” and “b” are of types “int”
and “float”, which are built-in data types. Hence the addition operator ‘+’ can easily add the contents of
“a” and “b”. This is because the addition operator “+” is predefined to add variables of built-in data type
only.
#Encapsulation in C++ is defined as the wrapping up of data and information in a single unit. In Object
Oriented Programming, Encapsulation is defined as binding together the data and the functions that
manipulate them Now there may arise a situation when for some reason an official from the finance
section needs all the data about sales in a particular month.//In this case, he is not allowed to directly
access the data of the sales section. He will first have to contact some other officer in the sales section
and then request him to give the particular data.//This is what //Encapsulation is. Here the data of the
sales section and the employees that can manipulate them are wrapped under a single name “sales
section”. //Two Important property of Encapsulation //Data Protection: Encapsulation protects the
internal state of an object by keeping its data members private. Access to and modification of these data
members is restricted to the class’s public methods, ensuring controlled and secure data manipulation.
///Information Hiding: Encapsulation hides the internal implementation details of a class from external
code. Only the public interface of the class is accessible, providing abstraction and simplifying the usage
of the class while allowing the internal implementation to be modified without impacting external code.
#Data Abstraction in C++//Data Abstraction is a process of providing only the essential details to the
outside world and hiding the internal details.//Data Abstraction is a programming technique that
depends on the seperation of the interface and implementation details of the program.//Let's take a real
life example of AC, which can be turned ON or OFF, change the temperature, change the mode, and
other external components such as fan, swing. But, we don't know the internal details of the AC, i.e., how
it works internally. Thus, we can say that AC seperates the implementation details from the external
interface.//C++ provides a great level of abstraction. For example, pow() function is used to calculate the
power of a number without knowing the algorithm the function follows.//In C++ program if we implement
class with private and public members then it is an example of data abstraction.// Public
specifier: When the members are declared as public, members can be accessed anywhere from the
program.//Private specifier: When the members are declared as private, members can only be
accessed only by the member functions of the class.
#Polymorphism means "many forms", and it occurs when we have many classes that are related to each
other by inheritance.//Like we specified in the previous chapter; Inheritance lets us inherit attributes
and methods from another class. Polymorphism uses those methods to perform different tasks. This
allows us to perform a single action in different ways.//For example, think of a base class
called Animal that has a method called animal Sound(). Derived classes of Animals could be Pigs, Cats,
Dogs, Birds - And they also have their own implementation of an animal sound (the pig oinks, and the cat
meows Key Concepts: Inheritance :Polymorphism is often used in conjunction with inheritance, where
derived classes inherit properties and behaviors from a base class.// Base Class Pointers: You can use a
pointer to the base class to point to objects of derived classes, which allows you to treat them as if they
were objects of the base class. //Virtual Function Table //(vtable) :The compiler creates a vtable for
each polymorphic class, which contains the addresses of the virtual functions. This table is used to
determine which function to call at runtime.