80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
Inheritance
1. Inheritance 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.
2. Example: 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.
3. Advantages Reusability: 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. Saves Time and Effort: 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.
4. Polymorphism 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.
5. Types of Polymorphism: C++ provides three different types of polymorphism. Virtual functions Function name overloading Operator overloading
6. Other types of polymorphism run-time: The run-time polymorphism is implemented with inheritance and virtual functions. Compile-time: The compile-time polymorphism is implemented with templates. ad-hoc polymorphism: 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. parametric polymorphism: 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.
7. stacks 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.
8. Member functions (constructor) Construct stack empty Test whether container is empty size Return size top Access next element push Add element pop Remove element
9. Queues 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.
10. Member functions (constructor) Construct queue empty Test whether container is empty size Return size front Access next element back Access last element push Insert element pop Delete next element