There are three main types of constructors in object-oriented programming:
1. A default constructor requires no arguments and is used when no parameters are passed during object creation.
2. A parameterized constructor allows arguments to be passed during object creation.
3. A copy constructor initializes a new object from an existing object, such as initializing object c2 with the same values as c1.
2. Default Constructor
1. Default Constructor is also called as no
argument constructor
2. This constructor has no arguments in it.
3. Parameterized Constructor
1. A constructor that can take arguments are
called parameterized constructors.
2. A parameterized constructor is just one that
has parameters specified in it.
3. We can pass the arguments to constructor
function when object are created.
4. Copy Constructor
1. Copy Constructor is used to declare and initialize
an object from another object.
2. For example the statement:
abc c2(c1);
would define the object c2 and at the same time
initialize it to the value of c1.
3.The process of initializing through a copy
constructor is known as copy initialization.
6. Encapsulation/Data hiding
"Hiding the Unnecessary¡°
?Encapsulation is hiding the
unnecessary.
?For example in the image the professor do not need
to know how a student does her assignment. He is
more interested in the end product.
7. Inheritance
"Modeling the Similarity"
? Similarities often exist in the world. As shown in
image above, one could easily see that there are
some similarities between the two President of
United States, George H.W Bush (41st President) and
George W. Bush (43rd President) George W. Bush is a son of George H.W Bush. He
inherits biological features from his father, at the same time, has his own unique
feature that one could identify him as George W. Bush.
? This bring us to the idea of inheritance that models a ¡°is a¡± relationship
between
objects.
8. Polymorphism
"Same Function different behavior"
? The word ¡°Polymorphism¡± comes from two Greek
words, ¡°many¡± and ¡°form¡±.
? We can illustrate the idea of polymorphism easily using the
scenario where different animals are asked to ¡°speak¡±. As
you can see from the image above, each animal has their
own way of ¡°speaking¡±.
? This illustrates the power of polymorphism where different
instances can be treated the same way.