Вы находитесь на странице: 1из 16

j=size-1;

program is displaying the transpose of matrix.


Pointers 20
Write a C++ program OOPs 24

Using Constructor and


Destructor
Polymorphism Concept

Same function but with Same function and same


more number of parameters but with
parameters different signatures
1) Compile time Polymorphism Operator Overloading Polymorphism Concept
Another Example We can make
base class's
methods
virtual by
using virtual
keyword while
declaring
them. Virtual
keyword will
When we use lead to Late
Base class's Binding of that
pointer to hold method.
Derived
class's object,
base class
pointer or
reference will
always call the
base version
of the function
Rules of Abstract Class
1) As we have seen that any class that has a pure virtual
function is an abstract class.
2) We cannot create the instance of abstract class.
For example: If I have written this line Animal obj; in the above
program, it would have caused compilation error.
3) We can create pointer and reference of base abstract class
points to the instance of child class. For example, this is valid:

Animal *obj = new Dog();


obj->sound();
4) Abstract class can have constructors.
5) If the derived class does not implement the pure virtual function of
parent class then the derived class becomes abstract.
Function
As we know that a class cannot access the private members of other class. Similarly a class Class
that doesn’t inherit another class cannot access its protected members.
Friend Class: A friend class is a class that can access the private and protected members of Example
a class in which it is declared as friend. This is needed when we want to allow a particular
class to access the private and protected members of a class
Friend Class and Friend Functions in C++
In this example we have two classes XYZ and ABC. The XYZ class has two private data
members ch and num, this class declares ABC as friend class. This means that ABC can
access the private members of XYZ, the same has been demonstrated in the example where Function
the function disp() of ABC class accesses the private members num and ch. In this example Function
we are passing object as an argument to the function.
Example Friend
Function:
Similar to
friend class,
this function
can access the
private and
protected
members of
another class.
A global
function can
also be
declared as
friend as
shown in the
example
below:

Вам также может понравиться