1 / 9

Abstrat_classes

It is about abstract classes in opp concept

Ali108
Download Presentation

Abstrat_classes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OOP Abstract Classes and Concrete Derived Classes

  2. Ealy and late binding • Binding means matching the function call with the correct function definition by the compiler. It takes place either at compile time or at runtime • In early binding, the compiler matches the function call with the correct function definition at compile time. It is also known as Static Binding or Compile-time Binding • We have learned about function overriding in which the base and derived classes have functions with the same name, parameters and return type. In that case also, early binding takes place

  3. Early binding #include <iostream> using namespace std; class Animals { public: void sound() { cout << "This is parent class" << endl; } };

  4. class Dogs : public Animals { public: void sound() { cout << "Dogs bark" << endl; } }; int main() { Animals *a; Dogs d; a= &d; a -> sound(); // early binding return 0; } On calling the function sound() which is present in both the classes by the pointer 'a', the function of the parent class got called

  5. Late binding • In the case of late binding, the compiler matches the function call with the correct function definition at runtime. It is also known as Dynamic Binding or Runtime Binding. • In late binding, the compiler identifies the type of object at runtime and then matches the function call with the correct function definition • This can be achieved by declaring a virtual function

  6. Virtual function • Virtual Function is a member function of the base class which is overridden in the derived class. The compiler performs late binding on this function. • To make a function virtual, we write the keyword virtual before the function definition virtual void sound() { cout << "This is parent class" << endl; }

  7. Pure Virtual Function • Pure virtual function is a virtual function which has no definition. Pure virtual functions are also called abstract functions. • To create a pure virtual function, we assign a value 0 to the function as follows virtual void sound() = 0;

  8. Abstract Class • An abstract class is a class whose instances (objects) can't be made. We can only make objects of its subclass (if they are not abstract). Abstract class is also known as abstract base class. • An abstract class has at least one abstract function (pure virtual function) • Subclasses of an abstract base class must define the abstract method, otherwise, they will also become abstract classes • In an abstract class, we can also have other functions and variables apart from pure virtual function

  9. Concrete derive class • A concrete class is a subclass of an abstract class, which implements all its abstract method • The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share

More Related