Final presentation programming

Post on 11-Apr-2017

113 views 1 download

Transcript of Final presentation programming

Need for inheritance:

one basic reason behind this is the capability to express the inheritance relationship.

Another reason is the idea of reusability

one reason is transitive nature of inheritance

Advantages of inheritance:some time we need to repeat the code or we need to repeat the whole class properties. So it helps in various ways

it saves memory spaceit saves time

it will remove frustrationit increase reliability of the code

it saves the developing and testing efforts

Why we use inheritance?

To increase the reusability of the code and to make future usable for another classes.

we use the concept of inheritance

How inheritance can be achieved?

In the inheritance there will be a parent child relationship. There is

a class called in which all the properties are defined and

generally, it is refered as a base class. There is also another class in which is derived from the existing one are known as a derived class.

Inheritance Access SpecifiersPublic Inheritance

This inheritance mode is used mostly. In this the protected member

of Base class becomes protected members of Derived class and public

becomes public.

class B : public Aclass C : public B

Inheritance Access SpecifiersProtected Inheritance

In protected mode, the public and protected members of Base class becomes protected members of

Derived class.

class B : protected Aclass C : protected B

Inheritance Access Specifiers

Private InheritanceIn private mode the public and

protected members of Base class become private members of Derived

class.

class B : private Aclass C : private B

Types of inheritanceThere are different types of

inheritance

single inheritanceMultiple inheritance

Hierarchical inheritancemultilevel inheritance

hybrid inheritance

Single inheritanceSingle inheritance enables a

derived class to inherit properties and behavior from a single parent class. It allows a

derived class to inherit the properties and behavior of a

base class, thus enabling code reusability as well as adding new

features to the existing code.

syntaxclass A

{--------------

};

class D : access specifier A{

--------------

};

Derived classIn Inheritance you create new

classes from existing class. Any new class that you create from an

existing class is called derived class.

Base classexisting class is called base class.

SOURCE CODE

OUTPUT:POSITION=0POSITION=1POSITION=0