Posts

Showing posts from February, 2020

Hybrid Inheritence in C++

Image
The inheritance in which the derivation of a class involves more than one form of any inheritance is called hybrid inheritance . Basically C++ hybrid inheritance is combination of two or more types of inheritance. It can also be called multi path inheritance. Following block diagram highlights the concept of hybrid inheritance which involves single and multiple inheritance . C++ Hybrid Inheritance Block Diagram Above block diagram shows the hybrid combination of single inheritance and multiple inheritance. Hybrid inheritance is used in a situation where we need to apply more than one inheritance in a program. As in other inheritance, based on the visibility mode used or access specifier used while deriving, the properties of the base class are derived. Access specifier can be private, protected or public. C++ Hybrid Inheritance Syntax   class A { ......... }; class B : public A { .......... } ; class C { ........... }; class D : public B , pu

Hierarchical Inheritance in C++

Image
 C++ Hierarchical Inheritance When several classes are derived from common base class it is called hierarchical inheritance . In C++ hierarchical inheritance , the feature of the base class is inherited onto more than one sub-class. For example, a car is a common class from which Audi, Ferrari, Maruti etc can be derived. Following block diagram highlights its concept. Hierarchical Inheritance Block Diagram As shown in above block diagram, in C++ hierarchical inheritance all the derived classes have common base class. The base class includes all the features that are common to derived classes. As in other inheritance, based on the visibility mode used or access specifier used while deriving, the properties of the base class are derived. Access specifier can be private, protected or public. Click here to learn in detail about access specifiers and their use in inheritance   C++ Hierarchical Inheritance Syntax class A // base cl

Multilevel Inheritence in C++

Multilevel Inheritance in C++ Programming Inheritance  is the process of inheriting properties of objects of one class by objects of another class. The class which inherits the properties of another class is called Derived or Child or Sub class and the class whose properties are inherited is called Base or Parent or Super class. When a class is derived from a class which is also derived from another class, i.e. a class having more than one parent classes, such inheritance is called Multilevel Inheritance . The level of inheritance can be extended to any number of level depending upon the relation. Multilevel inheritance is similar to relation between grandfather, father and child. For example , Student is derived from person and person is derived from class living things. Car is derived from vehicle and vehicle is derived from machine. Syntax of Multilevel Inheritance class base_classname {     properties;     methods; }; class intermediate_classname:vi

Multiple Inheritence in C++

Image
If a class is derived from two or more base classes then it is called multiple inheritance. In C++ multiple inheritance a derived class has more than one base class. How does multiple inheritance differ from multilevel inheritance? Though but multiple and multilevel sounds like same but they differ hugely in meaning. In multilevel inheritance , we have multiple parent classes whereas in in multiple inheritance we have multiple base classes. To put it in simple words, in multilevel inheritance, a class is derived from a class which is also derived from another base class. And these levels of inheritance can be extended. On the contrary, in multiple inheritance, a class is derived from two different base classes. For example Multilevel inheritance : Inheritance of characters by a child from father and father inheriting characters from his father (grandfather) Multiple inheritance : Inheritance of characters by a child from mother and father C++ Multiple Inheritan

Single Inheritence In C++

Image
A Derived class is defined as the class derived from the base class. The Syntax of Derived class: class  derived_class_name :: visibility-mode base_class_name   {        // body of the derived class.    }       Where, derived_class_name : It is the name of the derived class. visibility mode : The visibility mode specifies whether the features of the base class are publicly inherited or privately inherited. It can be public or private. base_class_name : It is the name of the base class. When the base class is privately inherited by the derived class, public members of the base class becomes the private members of the derived class. Therefore, the public members of the base class are not accessible by the objects of the derived class only by the member functions of the derived class. When the base class is publicly inherited by the derived class, public members of the base class also become the public members of the derived class. Therefore, the public

Types of Inheritence in C++

Image
C++ Inheritance Types C++ supports six types of inheritance as follows: Single Inheritance Multilevel Inheritance Multiple Inheritance Heirarchical Inheritance Hybrid Inheritance Multipath Inheritance Single Inheritance A derived class with only one base class is called single inheritance . Multilevel Inheritance A derived class with one base class and that base class is a derived class of another is called multilevel inheritance . Multiple Inheritance A derived class with multiple base class is called multiple inheritance . Heirarchical Inheritance Multiple derived classes with same base class is called hierarchical inheritance . Hybrid Inheritance Combination of multiple and hierarchical inheritance is called hybrid inheritance . Multipath Inheritance A derived class with two base classes and these two base classes have one common base class is called multipath inheritance .

OOPS Concepts in C++

Object oriented programming is a way of solving complex problems by breaking them into smaller problems using objects. Before Object Oriented Programming (commonly referred as OOP), programs were written in procedural language, they were nothing but a long list of instructions. On the other hand, the OOP is all about creating objects that can interact with each other, this makes it easier to develop programs in OOP as we can understand the relationship between them. Object Oriented Programming(OOP) In Object oriented programming we write programs using classes and objects utilising features of OOPs such as abstraction , encapsulation , inheritance and polymorphism Class and Objects A class is like a blueprint of data member and functions and object is an instance of class. For example, lets say we have a class Car which has data members (variables) such as speed, weight, price and functions such as gearChange(), slowDown(), brake() etc. Now lets say I create a objec

Difference Between C and C++

Image
Difference Between C and C++