Inheritance

651 views

Published on

Published in: Education, Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
651
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Inheritance

  1. 1. Inheritance<br />Inheritance is the process by which new classes called derived classes are created from existing classes called base classes. The derived classes have all the features of the base class and the programmer can choose to add new features specific to the newly created derived class.<br />
  2. 2. Example:<br />A programmer can create a base class named fruit and define derived classes as mango, orange, banana, etc. Each of these derived classes, (mango, orange, banana, etc.) has all the features of the base class (fruit) with additional attributes or features specific to these newly created derived classes. Mango would have its own defined features, orange would have its own defined features, banana would have its own defined features, etc. <br />
  3. 3. Advantages<br />Reusability: <br />Inheritance helps the code to be reused in many situations. The base class is defined and once it is compiled, it need not be reworked. Using the concept of inheritance, the programmer can create as many derived classes from the base class as needed while adding specific features to each derived class as needed. <br />Saves Time and Effort:<br />The above concept of reusability achieved by inheritance saves the programmer time and effort. Since the main code written can be reused in various situations as needed. <br />
  4. 4. Polymorphism<br />Polymorphism is the ability to use an operator or function in different ways. Polymorphism gives different meanings or functions to the operators or functions. Poly, referring to many, signifies the many uses of these operators and functions. A single function usage or an operator functioning in many ways can be called polymorphism. Polymorphism refers to codes, operations or objects that behave differently in different contexts. <br />
  5. 5. Types of Polymorphism: <br />C++ provides three different types of polymorphism. <br />Virtual functions <br />Function name overloading <br />Operator overloading <br />
  6. 6. Other types of polymorphism<br />run-time:<br />The run-time polymorphism is implemented with inheritance and virtual functions. <br />Compile-time: <br />The compile-time polymorphism is implemented with templates. <br />ad-hoc polymorphism:<br />If the range of actual types that can be used is finite and the combinations must be individually specified prior to use, this is called ad-hoc polymorphism. <br />parametric polymorphism: <br />If all code is written without mention of any specific type and thus can be used transparently with any number of new types it is called parametric polymorphism. <br />
  7. 7. stacks<br />Stacks are a type of container adaptors, specifically designed to operate in a LIFO context (last-in first-out), where elements are inserted and extracted only from the end of the container.<br />
  8. 8. Member functions<br />(constructor) Construct stack<br />empty Test whether container is empty<br />size Return size<br />top Access next element<br />push Add element<br />pop Remove element<br />
  9. 9. Queues<br />Queues are a type of container adaptors, specifically designed to operate in a FIFO context (first-in first-out), where elements are inserted into one end of the container and extracted from the other.<br />
  10. 10. Member functions<br />(constructor) Construct queue<br />empty Test whether container is empty<br />size Return size<br />front Access next element<br />back Access last element<br />push Insert element<br />pop Delete next element<br />

×