ABSTRACT CLASS
Name: Md. Sujan Mia
Session: 2016-17
Id: 154085
OVERVIEW OF ABSTRACT CLASS?
 What is abstract class?
 How to make abstract class ?
 How to use abstract class ?
 Importance of abstract class ?
WHAT IS ABSTRACT CLASS?
Abstract class :
 An abstract class is a class that is designed to
be specific used as a base class .
 we can’t create objects of abstract classes.
 An abstract class contains at least one pure
base class.
HOW TO MAKE ABSTRACT CLASS?
 An abstract class contains at least one pure virtual
function. Declare a pure virtual function by using a
pure specifier (= 0) in the declaration of a virtual
member function.
The following is an example of an abstract class:
class abstract
{
public:
virtual void f() = 0; //pure virtual function that
};
HOW TO USE ABSTRACT CLASS ?
//this is simple program of abstract class.
#include <iostream>
using namespace std;
class Abstract {
int x, y;
public:
virtual void setData(int x = 0, int y = 0) = 0; //pure virtual member
virtual void printData() = 0;
};
class Derived : public Abstract {
int x, y;
public:
void setData(int a= 0, int b= 0)
{
x = a;
y = b;
}
void printData()
{
cout << "Derived::x = " << x << endl
<< "Derived::y = " << y << endl;
}
};
int main()
{
Derived d;
//new data set.
d.setData(10, 20);
cout << “Set New data " << endl;
d.printData();
}
OUTPUT:
Set New data:
Derived::x =10
Derived::y=20
IMPORTANCE OF ABSTRACT CLASS?
 An abstract class as a base class is needed
when there is functionality that is desired for
all objects that have a type deriving from
Abstract Class, but we cannot be
implemented on the Abstract Class itself.
THANK YOU

Abstract class in c++

  • 1.
    ABSTRACT CLASS Name: Md.Sujan Mia Session: 2016-17 Id: 154085
  • 2.
    OVERVIEW OF ABSTRACTCLASS?  What is abstract class?  How to make abstract class ?  How to use abstract class ?  Importance of abstract class ?
  • 3.
    WHAT IS ABSTRACTCLASS? Abstract class :  An abstract class is a class that is designed to be specific used as a base class .  we can’t create objects of abstract classes.  An abstract class contains at least one pure base class.
  • 4.
    HOW TO MAKEABSTRACT CLASS?  An abstract class contains at least one pure virtual function. Declare a pure virtual function by using a pure specifier (= 0) in the declaration of a virtual member function. The following is an example of an abstract class: class abstract { public: virtual void f() = 0; //pure virtual function that };
  • 5.
    HOW TO USEABSTRACT CLASS ? //this is simple program of abstract class. #include <iostream> using namespace std; class Abstract { int x, y; public: virtual void setData(int x = 0, int y = 0) = 0; //pure virtual member virtual void printData() = 0; }; class Derived : public Abstract { int x, y; public: void setData(int a= 0, int b= 0) { x = a; y = b; }
  • 6.
    void printData() { cout <<"Derived::x = " << x << endl << "Derived::y = " << y << endl; } }; int main() { Derived d; //new data set. d.setData(10, 20); cout << “Set New data " << endl; d.printData(); } OUTPUT: Set New data: Derived::x =10 Derived::y=20
  • 7.
    IMPORTANCE OF ABSTRACTCLASS?  An abstract class as a base class is needed when there is functionality that is desired for all objects that have a type deriving from Abstract Class, but we cannot be implemented on the Abstract Class itself.
  • 8.