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 />
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 />
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 />
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 />
Types of Polymorphism: <br />C++ provides three different types of polymorphism. <br />Virtual functions <br />Function name overloading <br />Operator overloading <br />
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 />
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 />
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 />
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 />
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 />
A particular slide catching your eye?
Clipping is a handy way to collect important slides you want to go back to later.