OOPS Assignment Part B - Harsha (1)

OOPS Assignment Part B - Harsha (1) - Inheritance and...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Inheritance and Polymorphism Introduction: This part of the document deals with the two major and important features of OOPs Inheritance Polymorphism This file documents all the features of Inheritance and Polymorphism using C++. All the concepts are explained with relevant examples and programs. Inheritance: Creating or deriving a new class using another class as a base is called inheritance in C++. The new class created is called a Derived class and the old class used as a base is called a Base class in C++ inheritance terminology. Inheritance is very similar to a parent-child Relationship. When a class is inherited the entire functions and data member are inherited, although not all of them will be accessible by the member functions of the derived class. But there are some exceptions to it too . Exceptions with respect to inheritance: Constructors and destructors of the base class are not inherited. Assignment operator is not inherited. Friend functions are not inherited. Different types of Inheritance: We can classify inheritance into different types Single Inheritance Multiple Inheritance Multilevel Hierarchical Inheritance Note: in the C++ code I have used only hierarchical Inheritance. Single Inheritance When only one class is derived from a single base class such derivation of a class is known as Single Inheritance . And one important thing is the derived class is not used as a base class further. Multiple Inheritance When a class is derived from more than one base class it is called as Multiple Inheritance. A class can be derived by inheriting the properties of more than once class. Multilevel Inheritance The procedure of deriving a class from a derived class is called Multilevel Inheritance. The above figure depicts Multilevel inheritance. B is derived from A and C is in turn derived from B. Hierarchical Inheritance In this type of inheritance one base class has more than one derived class. As shown in the figure. Base Class A Derived Class B A B C D A B C The code included in the appendix uses hierarchical inheritance to implement the concepts of inheritance and polymorphism. Polymorphism Polymorphism is a technique in which various forms of a single function can be defined and shared by various objects to perform the operation. In C++ we can attain polymorphism using Virtual keyword. In the main function I created a single pointer for the base class...
View Full Document

This note was uploaded on 02/22/2011 for the course CS 541 taught by Professor Dr.marcosrodrigues during the Spring '09 term at SUNY Buffalo.

Page1 / 13

OOPS Assignment Part B - Harsha (1) - Inheritance and...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online